Esempio n. 1
0
        private static void ListInstrumentsJSON(WebContext context, Song s)
        {
            JSONWriter jw = new JSONWriter();
            jw.Array();

            for (int k = 0; k < s.Instruments.Count; k++)
            {
                Instrument ins = s.Instruments[k];

                jw.Class();
                jw.Field("id", ins.ID);
                jw.Field("name", ins.Name);
                jw.Field("device", ins.MidiDevice);
                jw.Field("channel", ins.MidiChannel);
                jw.Field("patch", ins.MidiPatch);
                jw.Field("type", ins.Type);
                jw.End();
            }

            jw.End();

            context.Response.Write("g_Instruments = ");
            context.Response.Write(jw.ToString(JSONFormatting.Pretty));
            context.Response.Write(";\n");
        }
Esempio n. 2
0
        public static string ToString(Table table, TableContainType tableContainType)
        {
            java.io.StringWriter stringWriter = new java.io.StringWriter();
            try
            {
                technology.tabula.writers.Writer writer = null;
                switch (tableContainType)
                {
                case TableContainType.CSV:
                    writer = new CSVWriter();
                    break;

                case TableContainType.Json:
                    writer = new JSONWriter();
                    break;

                case TableContainType.TSV:
                    writer = new TSVWriter();
                    break;

                default:
                    writer = new JSONWriter();
                    break;
                }

                writer.write(stringWriter, table);
            }
            catch
            {
                return(string.Empty);
            }
            return(stringWriter.toString());
        }
Esempio n. 3
0
        public void OnDefault(SynkContext context)
        {
            var entityClass = context.request.GetVariable("entity");
            var term        = context.request.GetVariable("term");
            var required    = context.request.GetVariable("required").Equals("true");

            List <Entity> entities = context.currentModule.Search(context, entityClass, term);

            var result = DataNode.CreateArray();

            if (!required)
            {
                var item = DataNode.CreateObject();
                item.AddField("value", "0");
                item.AddField("label", context.Translate("system_none"));
                result.AddNode(item);
            }

            if (entities != null)
            {
                foreach (var entity in entities)
                {
                    var item = DataNode.CreateObject();
                    item.AddField("value", entity.id.ToString());
                    item.AddField("label", entity.ToString());
                    result.AddNode(item);
                }
            }

            var json = JSONWriter.WriteToString(result);

            context.Echo(json);
        }
        public string getCustomSetting(string settingname)
        {
            JSONWriter writer = new JSONWriter();

            writer.WriteStartArray();
            foreach (CustomSetting setting in CustomSettings)
            {
                if (setting.SettingName == settingname.ToLower())
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("Name");
                    writer.WriteValue(setting.SettingName);
                    writer.WritePropertyName("Private");
                    writer.WriteValue(setting.Private);
                    writer.WritePropertyName("Value");
                    writer.WriteValue(setting.Value);
                    writer.WriteEndObject();

                    break;
                }
            }
            writer.WriteEndArray();

            return(writer.GetString());
        }
Esempio n. 5
0
        private static void SaveGame()
        {
            var save = ProperSavePlugin.CurrentSave = new SaveFile
            {
                SaveFileMeta = SaveFileMetadata.GetCurrentLobbySaveMetadata() ?? SaveFileMetadata.CreateMetadataForCurrentLobby()
            };

            if (string.IsNullOrEmpty(save.SaveFileMeta.FileName))
            {
                do
                {
                    save.SaveFileMeta.FileName = Guid.NewGuid().ToString();
                }while (File.Exists(save.SaveFileMeta.FilePath));
            }

            try
            {
                var json = JSONWriter.ToJson(save);
                File.WriteAllText(save.SaveFileMeta.FilePath, json);

                SaveFileMetadata.AddIfNotExists(save.SaveFileMeta);
                Chat.AddMessage(Language.GetString(LanguageConsts.PS_CHAT_SAVE));
            }
            catch (Exception e)
            {
                ProperSavePlugin.InstanceLogger.LogWarning("Failed to save the game");
                ProperSavePlugin.InstanceLogger.LogError(e);
            }
        }
Esempio n. 6
0
        public HTTPResponse ResponseFromObject(object obj, HTTPCode code)
        {
            if (obj is HTTPResponse)
            {
                return((HTTPResponse)obj);
            }

            if (obj is string)
            {
                return(HTTPResponse.FromString((string)obj, code, Settings.Compression));
            }

            if (obj is byte[])
            {
                return(HTTPResponse.FromBytes((byte[])obj));
            }

            if (obj is DataNode)
            {
                var root = (DataNode)obj;
                var json = JSONWriter.WriteToString(root);
                return(HTTPResponse.FromString(json, code, Settings.Compression, "application/json"));
            }

            var type = obj.GetType();

            Logger(LogLevel.Error, $"Can't serialize object of type '{type.Name}' into HTTP response");
            return(null);
        }
Esempio n. 7
0
    public bool tryAttackPlayer(int attacker_id, Position attacker_pos)
    {
        JSONObject message = JSONWriter.attackPlayerJSON(attacker_id, attacker_pos);

        send(message.ToString());
        return(readAck("Attack" + control.getPlayerId() + " ack"));
    }
        /// <summary>
        /// This method is the main entry point to create the various weekly JSON
        /// analysis files. A total of four files will be created, one for each
        /// type of analysis (DropRAT, DropMixBand, FailRAT, FailMixBand) within the
        /// specified output directory. Minification of the file is available to
        /// save space if required.
        /// </summary>
        /// <param name="directory">The output directory</param>
        /// <param name="minify">Whether or not to minify the results</param>
        public void CreateWeeklyAnalysisJSON(String directory, Boolean minify = true)
        {
            // Ensure there is a trailing backslash upon the directory
            directory = directory.TrimEnd('\\') + @"\";

            // Obtain the JSON String
            String drop_rats     = MergeDropRATJSON();
            String drop_mixbands = MergeDropMixBandJSON();
            String fail_rats     = MergeFailRATJSON();
            String fail_mixbands = MergeFailMixBandJSON();

            // Check to see if the output requires prettifying (un-minifying)
            if (!minify)
            {
                drop_rats     = JSONWriter.PrettifyJSON(drop_rats);
                drop_mixbands = JSONWriter.PrettifyJSON(drop_mixbands);
                fail_rats     = JSONWriter.PrettifyJSON(fail_rats);
                fail_mixbands = JSONWriter.PrettifyJSON(fail_mixbands);
            }

            // Create each output file
            File.WriteAllText(directory + "weekly_drop_rat.json", drop_rats);
            File.WriteAllText(directory + "weekly_drop_mix_band.json", drop_mixbands);
            File.WriteAllText(directory + "weekly_fail_rat.json", fail_rats);
            File.WriteAllText(directory + "weekly_fail_mix_band.json", fail_mixbands);
        }
Esempio n. 9
0
        public void TestJSONArrayWriter()
        {
            var root = DataNode.CreateArray(null);

            root.AddField(null, "hello");
            root.AddField(null, "1");
            root.AddField(null, "2");

            var json = JSONWriter.WriteToString(root);

            Assert.NotNull(json);

            var other = JSONReader.ReadFromString(json);

            Assert.NotNull(other);

            Assert.IsTrue(other.ChildCount == root.ChildCount);

            for (int i = 0; i < root.ChildCount; i++)
            {
                var child      = root.GetNodeByIndex(i);
                var otherChild = other.GetNodeByIndex(i);

                Assert.NotNull(child);
                Assert.NotNull(otherChild);

                Assert.IsTrue(child.Name == otherChild.Name);
                Assert.IsTrue(child.Value == otherChild.Value);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Writes row as JSON either as an array or map depending on JSONWritingOptions.RowsAsMap setting.
        /// Do not call this method directly, instead call rowset.ToJSON() or use JSONWriter class
        /// </summary>
        public void WriteAsJSON(System.IO.TextWriter wri, int nestingLevel, JSONWritingOptions options = null)
        {
            if (options == null || !options.RowsAsMap)
            {
                JSONWriter.WriteArray(wri, this, nestingLevel, options);
                return;
            }

            var map = new Dictionary <string, object>();

            foreach (var fd in Schema)
            {
                map.Add(fd.Name, GetFieldValue(fd));
            }

            if (this is IAmorphousData)
            {
                var amorph = (IAmorphousData)this;
                if (amorph.AmorphousDataEnabled)
                {
                    foreach (var kv in amorph.AmorphousData)
                    {
                        var key = kv.Key;
                        while (map.ContainsKey(key))
                        {
                            key += "_";
                        }
                        map.Add(key, kv.Value);
                    }
                }
            }

            JSONWriter.WriteMap(wri, map, nestingLevel, options);
        }
Esempio n. 11
0
        public static DataNode Request(RequestType kind, string url, DataNode data = null)
        {
            string contents;

            switch (kind)
            {
            case RequestType.GET: contents = GetWebRequest(url); break;

            case RequestType.POST:
            {
                var paramData = data != null?JSONWriter.WriteToString(data) : "{}";

                contents = PostWebRequest(url, paramData);
                break;
            }

            default: return(null);
            }


            File.WriteAllText("response.json", contents);

            var root = JSONReader.ReadFromString(contents);

            return(root);
        }
Esempio n. 12
0
        public void TestJSONObjectWriter()
        {
            var color = new Color(200, 100, 220, 128);
            var root  = DataNode.CreateObject(null);

            root.AddNode(color.ToDataNode());

            var json = JSONWriter.WriteToString(root);

            Assert.NotNull(json);

            var other = JSONReader.ReadFromString(json);

            Assert.NotNull(other);

            Assert.IsTrue(other.ChildCount == root.ChildCount);

            for (int i = 0; i < root.ChildCount; i++)
            {
                var child      = root.GetNodeByIndex(i);
                var otherChild = other.GetNodeByIndex(i);

                Assert.NotNull(child);
                Assert.NotNull(otherChild);

                Assert.IsTrue(child.Name == otherChild.Name);
                Assert.IsTrue(child.Value == otherChild.Value);
            }
        }
Esempio n. 13
0
        public bool Save(string fileName)
        {
            this.fileName = fileName;

            var result = DataNode.CreateObject("blockchain");

            for (uint i = 1; i <= _blocks.Count; i++)
            {
                var block = _blocks[i];
                result.AddNode(block.Save());
            }

            foreach (var address in _accounts)
            {
                result.AddNode(address.Save());
            }

            try
            {
                var json = JSONWriter.WriteToString(result);
                File.WriteAllText(fileName, json);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 14
0
        public void Save()
        {
            var root = DataNode.CreateObject("settings");

            root.AddField("lastfile", this.lastOpenedFile);
            root.AddField("lastkey", this.lastPrivateKey);

            var paramsNode = DataNode.CreateArray("lastparams");

            foreach (var entry in lastParams)
            {
                var node = DataNode.CreateObject();
                node.AddField("key", entry.Key);
                node.AddField("value", entry.Value);
                paramsNode.AddNode(node);
            }
            root.AddNode(paramsNode);

            var compilersNode = DataNode.CreateArray("compilers");

            foreach (var entry in this.compilerPaths)
            {
                var node = DataNode.CreateObject();
                node.AddField("language", entry.Key);
                node.AddField("path", entry.Value);
                compilersNode.AddNode(node);
            }
            root.AddNode(compilersNode);

            var json = JSONWriter.WriteToString(root);

            Directory.CreateDirectory(this.path);

            File.WriteAllText(fileName, json);
        }
Esempio n. 15
0
        private static void SaveGame()
        {
            Save = new SaveData();
            var metadata      = SaveFileMeta.CreateCurrentMetadata();
            var foundMetadata = GetLobbySaveMetadata();

            Save.SaveFileMeta = foundMetadata ?? metadata;
            if (string.IsNullOrEmpty(Save.SaveFileMeta.FileName))
            {
                do
                {
                    Save.SaveFileMeta.FileName = Guid.NewGuid().ToString();
                }while (File.Exists(Save.SaveFileMeta.FilePath));
            }

            try
            {
                var json = JSONWriter.ToJson(Save);
                File.WriteAllText(Save.SaveFileMeta.FilePath, json);
                if (ReferenceEquals(Save.SaveFileMeta, metadata))
                {
                    SavesMetadata.Add(metadata);
                    UpdateSavesMetadata();
                }
                Chat.AddMessage(Language.GetString(LanguageConsts.PS_CHAT_SAVE));
            }
            catch (Exception e)
            {
                Debug.LogWarning("[ProperSave] Couldn't save game");
            }
        }
Esempio n. 16
0
    public bool tryMoveCharacter(Card card, Position position)
    {
        JSONObject message = JSONWriter.moveCharacterJSON(card, position);

        send(message.ToString());
        return(readAck("Move" + control.getPlayerId() + " ack"));
    }
Esempio n. 17
0
        /// <summary>
        /// Writes schema as JSON. Do not call this method directly, instead call rowset.ToJSON() or use JSONWriter class
        /// </summary>
        public void WriteAsJSON(System.IO.TextWriter wri, int nestingLevel, JSONWritingOptions options = null)
        {
            IEnumerable <FieldDef> defs = m_FieldDefs;

            if (options != null && options.RowMapTargetName.IsNotNullOrWhiteSpace())
            {
                var newdefs = new List <FieldDef>();
                foreach (var def in defs)
                {
                    FieldAttribute attr;
                    var            name = def.GetBackendNameForTarget(options.RowMapTargetName, out attr);
                    if (attr != null)
                    {
                        if (attr.StoreFlag == StoreFlag.None || attr.StoreFlag == StoreFlag.OnlyLoad)
                        {
                            continue;
                        }
                    }
                    newdefs.Add(def);
                }
                defs = newdefs;
            }

            var map = new Dictionary <string, object>
            {
                { "Name", "JSON" + m_Name.GetHashCode() },
                { "FieldDefs", defs }
            };

            JSONWriter.WriteMap(wri, map, nestingLevel, options);
        }
Esempio n. 18
0
    /// <summary>
    /// joga magia sem alvo - Exemplo: Nevasca (cause 2 de dano a todos personagens)
    /// </summary>
    /// <param name="magic_id"></param>
    /// <returns></returns>
    public bool tryPlayMagicWithoutTarget(int magic_id)
    {
        JSONObject json = JSONWriter.tryPlayMagic(magic_id);

        send(json.ToString());
        return(readAck("Play spell" + control.getPlayerId() + " ack"));
    }
Esempio n. 19
0
    //play a 1 size character on the line/position on the battlefield
    public bool tryPlayCharacter(Card card, Position pos, int hand_index)
    {
        int        id      = control.getPlayerId();
        JSONObject message = JSONWriter.playCharacterJSON(card, id, hand_index, pos);

        send(message.ToString());
        return(readAck("PlayCharacter" + control.getPlayerId() + " ack"));
    }
        public void TestAnswers()
        {
            var path    = Path.Combine(Path.GetDirectoryName(this.GetType().Assembly.Location), "testdir");
            var wiki    = Dialogflow.Wiki.Core.Wiki.ParseDir(path);
            var destDir = Path.Combine(Path.GetDirectoryName(this.GetType().Assembly.Location), "generated");

            JSONWriter.WriteAnswers(wiki.Intents, destDir);
        }
        public void SerializeJson(JSONWriter writer)
        {
            writer.WriteStartArray();

            lineInfos.ForEach(x => x.SerializeJson(writer));

            writer.WriteEndArray();
        }
Esempio n. 22
0
        public void SaveSettings()
        {
            //没有能力处理异常(参见JSONWriter类中的异常类型)
            JSONWriter writer = new JSONWriter(SettingsPath);

            writer.WriteJSON <JObject>(this.Value);
            return;
        }
Esempio n. 23
0
 public void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null)
 {
     JSONWriter.WriteMap(wri,
                         nestingLevel + 1,
                         options,
                         new DictionaryEntry("$timestamp", new { t = EpochSeconds, i = Increment })
                         );
 }
Esempio n. 24
0
 public void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null)
 {
     JSONWriter.WriteMap(wri,
                         nestingLevel + 1,
                         options,
                         new DictionaryEntry("$oid", Convert.ToBase64String(Bytes))
                         );
 }
Esempio n. 25
0
 public override void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null)
 {
     JSONWriter.WriteMap(wri,
                         nestingLevel + 1,
                         options,
                         new DictionaryEntry("$maxKey", 1)
                         );
 }
Esempio n. 26
0
 public override void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null)
 {
     JSONWriter.WriteMap(wri,
                         nestingLevel + 1,
                         options,
                         new DictionaryEntry("$numberLong", Value)
                         );
 }
Esempio n. 27
0
        public void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null)
        {
            var data = new Dictionary <string, object>();

            WriteJSONFields(data, options);

            JSONWriter.WriteMap(wri, data, nestingLevel, options);
        }
Esempio n. 28
0
 public void WriteAsJSON(System.IO.TextWriter wri, int nestingLevel, JSONWritingOptions options = null)
 {
     wri.Write('{');
     wri.Write("\"iso\":"); JSONWriter.EncodeString(wri, m_CurrencyISO, options);
     wri.Write(',');
     wri.Write("\"v\":"); wri.Write(m_Value);
     wri.Write('}');
 }
Esempio n. 29
0
    public void toExhibit(Button btn)
    {
        title_header.text = "Gallery 161";

        exhibitDisplay.SetActive(true);
        json.currWork = JSONWriter.ExtractJSONFile(json.gallery161_003);
        json.WriteStats(json.currWork);
    }
Esempio n. 30
0
 public void setBetAmountText(string new_value)
 {
     flagHasBetAmount = true;
     if (!(JSONWriter.is_valid_number_format(new_value)))
     {
         throw new Exception("The text value for field BetAmount of HandHistoryJSON is not a valid number.");
     }
     textStoreBetAmount = new_value;
 }
 public void setBrightnessLevelText(string new_value)
 {
     flagHasBrightnessLevel = true;
     if (!(JSONWriter.is_valid_number_format(new_value)))
     {
         throw new Exception("The text value for field BrightnessLevel of BrightnessCommandJSON is not a valid number.");
     }
     textStoreBrightnessLevel = new_value;
 }
Esempio n. 32
0
        private static void ListAutomationChannelsJSON(WebContext context, Song s)
        {
            JSONWriter jw = new JSONWriter();
            jw.Array();

            for (int j = 0; j < s.Tracks.Count; j++)
            {
                // SongTrack st = s.Tracks[j];
                jw.Class();
                jw.Field("id", j);
                jw.Field("name", "Automation #" + j);
                jw.End();
            }

            jw.End();

            context.Response.Write("g_AutomationTracks = ");
            context.Response.Write(jw.ToString(JSONFormatting.Pretty));
            context.Response.Write(";\n");
        }
Esempio n. 33
0
        public ActionResult Computers(string method, string id)
        {
            string token = Request["token"];
            string userid = APITokens.GetUserID(token);

            if (method == "get")
            {

            }
            else if (method == "list")
            {
                string username = Request["user"];

                JSONWriter jw = new JSONWriter();
                jw.Class();
                jw.Array("computers");

                DBDataContext db = new DBDataContext();

                IEnumerable<Computers> comps = from c in db.Computers orderby c.ComputerName ascending select c;

                if (!string.IsNullOrEmpty(username))
                    comps = from c in comps
                            where c.UserID.ToString().Equals(username)
                            select c;

                foreach (Computers c in comps)
                {
                    jw.Class();
                    jw.Field("id", c.ID);
                    jw.Field("name", c.ComputerName);
                    if (c.CreatedDate.HasValue)
                        jw.Field("date", c.CreatedDate.Value.ToString("R"));
                    if (c.Users != null)
                    {
                        jw.Field("userid", c.Users.UserID.ToString());
                        jw.Field("username", c.Users.UserName);
                    }

                    //					int totalused = (from v in db.Volumes, m in v.Measures select v.MeasureUsed select ).Sum();

                    int? totalused2 = 0;
                    try
                    {
                        totalused2 = (
                            from v2 in db.Volumes
                            where v2.ComputerID.Equals(c.ID)
                            select (
                            from m in v2.Measures where m.VolumeID.Equals(v2.ID) orderby m.MeasureDate descending select m.MeasureUsed
                            ).First()
                            ).Sum();

                    }
                    catch (Exception)
                    {
                    }

                    int? totalsize2 = 0;
                    try
                    {
                        totalsize2 = (
                            from v2 in db.Volumes
                            where v2.ComputerID.Equals(c.ID)
                            select (
                            from m in v2.Measures where m.VolumeID.Equals(v2.ID) orderby m.MeasureDate descending select m.MeasureSize
                            ).First()
                            ).Sum();
                    }
                    catch (Exception)
                    {
                    }

                    if (totalsize2.HasValue)
                        jw.Field("totalsize", totalsize2.Value);
                    else
                        jw.Field("totalsize", 0);

                    if (totalused2.HasValue)
                        jw.Field("totalused", totalused2.Value);
                    else
                        jw.Field("totalused", 0);

                    jw.Array("volumes");

                    IEnumerable<Volume> vols = from v in c.Volumes orderby v.VolumeName select v;
                    foreach (Volume v in vols)
                    {
                        jw.Class();
                        jw.Field("id", v.ID);
                        if (v.VolumeName != null)
                            jw.Field("name", v.VolumeName);
                        else
                            jw.Field("name", "");
                        int? numsamples = null;
                        try
                        {
                            numsamples = (from m in v.Measures where m.VolumeID.Equals(v.ID) select m).Count();
                        }
                        catch (Exception)
                        {
                        }

                        DateTime? lastsample = null;
                        try
                        {
                            lastsample = (from m in v.Measures where m.VolumeID.Equals(v.ID) orderby m.MeasureDate descending select m.MeasureDate).First();
                        }
                        catch (Exception)
                        {
                        }

                        int? totalused = 0;
                        try
                        {
                            totalused = (from m in v.Measures where m.VolumeID.Equals(v.ID) orderby m.MeasureDate descending select m.MeasureUsed).First();
                        }
                        catch (Exception)
                        {
                        }

                        int? totalsize = 0;
                        try
                        {
                            totalsize = (from m in v.Measures where m.VolumeID.Equals(v.ID) orderby m.MeasureDate descending select m.MeasureSize).First();
                        }
                        catch (Exception)
                        {
                        }

                        jw.Field("samples", numsamples.Value);
                        if (lastsample.HasValue)
                            jw.Field("last", lastsample.Value.ToString("R"));
                        jw.Field("used", totalused.Value);
                        jw.Field("size", totalsize.Value);
                        jw.End();
                    }
                    jw.End();
                    jw.End();

                }

                jw.End();
                jw.End();

                return new JSONResponseResult(jw.ToString(JSONFormatting.Pretty));

            }
            else if (method == "add")
            {
                if (string.IsNullOrEmpty(userid))
                    return new JSONResponseResult("not authenticated");

                string un = Request["username"];

                // int compid = 0;
                // int.TryParse(Request["computer"], out compid);

                int volid = 0;
                int.TryParse(Request["volume"], out volid);

                int ds = 0;
                int.TryParse(Request["disksize"], out ds);

                int du = 0;
                int.TryParse(Request["diskused"], out du);

                DBDataContext db = new DBDataContext();

                var user = from u in db.Users where u.UserName.Equals(un) select u;
                if (user != null)
                {

                    Measure m = new Measure();

                    m.MeasureSize = ds;
                    m.MeasureUsed = du;
                    m.VolumeID = volid;
                    m.MeasureDate = DateTime.Now;

                    db.Measures.InsertOnSubmit(m);
                    db.SubmitChanges();

                    return new JSONResponseResult("ok");
                }
            }
            else if (method == "remove")
            {
                if (string.IsNullOrEmpty(userid))
                    return new JSONResponseResult("not authenticated");
            }

            return new JSONResponseResult("unknown computers-command; method=" + method + ", id=" + id);
        }
Esempio n. 34
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["getinstrumentlist"] != null)
            {
                Song s = Global.CurrentSong;

                JSONWriter jw = new JSONWriter();
                jw.Class();
                jw.Array("instruments");
                for (int k = 0; k < s.Instruments.Count; k++)
                {
                    Instrument ins = s.Instruments[k];

                    jw.Class();
                    jw.Field("id", ins.ID);
                    jw.Field("name", ins.Name);
                    jw.Field("type", ins.Type);
                    jw.Field("midichannel", ins.MidiChannel);
                    jw.Field("midipatch", ins.MidiPatch);
                    jw.End();
                }
                jw.End();
                jw.End();
                AjaxUtilities.ReturnJSON(jw);
            }
            else if (Request["getpatternlist"] != null)
            {
                string ins = AjaxUtilities.GetStringParameter("getpatternlist");
                Song s = Global.CurrentSong;
                JSONWriter jw = new JSONWriter();
                jw.Class();
                jw.Array("patterns");
                for (int k = 0; k < s.Patterns.Count; k++)
                {
                    Pattern p = s.Patterns[k];
                    jw.Class();
                    jw.Field("id", p.ID);
                    jw.Field("name", p.Name);
                    jw.End();
                }
                jw.End();
                jw.End();
                AjaxUtilities.ReturnJSON(jw);
            }
            else if (Request["getpattern"] != null)
            {
                string patid = AjaxUtilities.GetStringParameter("getpattern");
                Pattern p = Global.CurrentSong.Patterns[0];

                JSONWriter jw = new JSONWriter();
                jw.Class();
                jw.Array("notes");
                for (int k = 0; k < p.Notes.Count; k++)
                {
                    PatternNote n = p.Notes[k];
                    jw.Class();
                    jw.Field("id", n.ID);
                    jw.Field("from", n.From);
                    jw.Field("to", n.To);
                    jw.Field("note", n.Note);
                    jw.Field("velocity", n.Velocity);
                    jw.End();
                }
                jw.End();
                jw.Array("automations");
                for (int k = 0; k < p.Automations.Count; k++)
                {
                    PatternAutomation am = p.Automations[k];
                    jw.Class();
                    jw.Field("id", am.ID);
                    jw.Field("channel", am.Channel);
                    jw.Field("macro", am.Macro);
                    jw.Array("points");
                    for (int j = 0; j < am.Keys.Count; j++)
                    {
                        PatternAutomationKey amk = am.Keys[j];
                        jw.Class();
                        jw.Field("id", amk.ID);
                        jw.Field("time", amk.Time);
                        jw.Field("value", amk.Value);
                        jw.End();
                    }
                    jw.End();
                    jw.End();
                }
                jw.End();
                jw.End();
                AjaxUtilities.ReturnJSON(jw);
            }
            else if (Request["getautomationchannels"] != null)
            {
                JSONWriter jw = new JSONWriter();
                jw.Class();
                jw.Array("channels");
                for (int k = 0; k < 127; k++)
                {
                    jw.Class();
                    jw.Field("id", k);
                    jw.Field("name", "Automation channel " + k);
                    jw.End();
                }
                jw.End();
                jw.End();
                AjaxUtilities.ReturnJSON(jw);

            }
            else if (Request["save"] != null)
            {
                Global.CurrentSong.SaveToFile(Server.MapPath("~/testsong-temp.xml"));
            }
            else if (Request["notify"] != null)
            {
                string n = AjaxUtilities.GetStringParameter("notify");
                if (n == "addnote")
                {
                    string id = "dummy000";
                    int from = AjaxUtilities.GetIntParameter("from");
                    int to = AjaxUtilities.GetIntParameter("to");
                    int note = AjaxUtilities.GetIntParameter("note");
                    int vel = AjaxUtilities.GetIntParameter("velocity");

                    // string pat = "pat0";
                    Song s = Global.CurrentSong;
                    Pattern p = s.Patterns[0];
                    p.Notes.Add(new PatternNote(id, from, to, note, vel));
                    Global.CurrentSong.SaveToFile(Server.MapPath("~/testsong-temp.xml"));
                }
                else if (n == "movenote")
                {
                    string id = AjaxUtilities.GetStringParameter("id");
                    int from = AjaxUtilities.GetIntParameter("from");
                    int to = AjaxUtilities.GetIntParameter("to");
                    int note = AjaxUtilities.GetIntParameter("note");
                    int vel = AjaxUtilities.GetIntParameter("velocity");

                    Song s = Global.CurrentSong;
                    Pattern p = s.Patterns[0];
                    PatternNote nt = p.GetNoteByID(id);
                    if (nt != null)
                    {
                        nt.From = from;
                        nt.To = to;
                        nt.Note = note;
                        nt.Velocity = vel;
                    }
                }
                else if (n == "deletenote")
                {
                    string id = AjaxUtilities.GetStringParameter("id");
                    Song s = Global.CurrentSong;
                    Pattern p = s.Patterns[0];
                    p.RemoveNoteByID(id);
                }
                else if (n == "")
                {
                }
                else if (n == "")
                {
                }
                else if (n == "")
                {
                }
            }
            else
            {

                Response.End();
            }
        }
Esempio n. 35
0
        private void GetMidiDeviceList(WebContext context)
        {
            string sid = context.Request.GetParameter("getmididevicelist");

            JSONWriter jw = new JSONWriter();
            jw.Class();
            jw.Array("devices");

            List<int> ids = MidiWrapper.GetDeviceIDs();

            for (int k = 0; k < ids.Count; k++)
            {
                string nam = MidiWrapper.GetDeviceName(ids[k]);
                jw.Class();
                jw.Field("id", ids[k]);
                jw.Field("name", nam);
                jw.End();
            }
            jw.End();
            jw.End();
            context.Response.ContentType = "text/javascript";
            context.Response.Write(jw.ToString());
        }
Esempio n. 36
0
 private void GetPatternList(WebContext context)
 {
     // string ins = context.Request.GetParameter("getpatternlist");
     Song s = State.CurrentSong;
     JSONWriter jw = new JSONWriter();
     jw.Class();
     jw.Array("patterns");
     for (int k = 0; k < s.Patterns.Count; k++)
     {
         Pattern p = s.Patterns[k];
         // if (p.InstrumentID == ins)
         {
             jw.Class();
             jw.Field("id", p.ID);
             jw.Field("name", p.Name);
             jw.End();
         }
     }
     jw.End();
     jw.End();
     context.Response.ContentType = "text/javascript";
     context.Response.Write(jw.ToString());
 }
Esempio n. 37
0
        private void GetPattern(WebContext context)
        {
            string pat = context.Request.GetParameter("getpattern");
            Song s = State.CurrentSong;
            Pattern p = s.GetPatternByID(pat);

            JSONWriter jw = new JSONWriter();
            jw.Class();
            jw.Field("id", p.ID);
            jw.Field("duration", p.Duration);
            jw.Field("name", p.Name);
            jw.Array("notes");
            for (int k = 0; k < p.Notes.Count; k++)
            {
                PatternNote n = p.Notes[k];
                jw.Class();
                jw.Field("id", n.ID);
                jw.Field("from", n.From);
                jw.Field("to", n.To);
                jw.Field("note", n.Note);
                jw.Field("velocity", n.Velocity);
                jw.End();
            }
            jw.End();
            jw.Array("automations");
            for (int k = 0; k < p.Automations.Count; k++)
            {
                PatternAutomation am = p.Automations[k];
                jw.Class();
                jw.Field("id", am.ID);
                jw.Field("channel", am.Channel);
                jw.Field("macro", am.Macro);
                jw.Array("points");
                for (int j = 0; j < am.Keys.Count; j++)
                {
                    PatternAutomationKey amk = am.Keys[j];
                    jw.Class();
                    jw.Field("id", amk.ID);
                    jw.Field("time", amk.Time);
                    jw.Field("value", amk.Value);
                    jw.End();
                }
                jw.End();
                jw.End();
            }
            jw.End();
            jw.End();
            context.Response.ContentType = "text/javascript";
            context.Response.Write(jw.ToString());
        }
Esempio n. 38
0
 private void GetInstrument(WebContext context)
 {
     string insid = context.Request.GetParameter("getinstrument");
     Song s = State.CurrentSong;
     JSONWriter jw = new JSONWriter();
     jw.Class();
     for (int k = 0; k < s.Instruments.Count; k++)
     {
         Instrument ins = s.Instruments[k];
         if (ins.ID == insid)
         {
             jw.Field("id", ins.ID);
             jw.Field("name", ins.Name);
             jw.Field("type", ins.Type);
             jw.Field("mididevice", ins.MidiDevice);
             jw.Field("midichannel", ins.MidiChannel);
             jw.Field("midipatch", ins.MidiPatch);
         }
     }
     jw.End();
     context.Response.ContentType = "text/javascript";
     context.Response.Write(jw.ToString());
 }
Esempio n. 39
0
        private static void ListPatternsJSON(WebContext context, Song s)
        {
            JSONWriter jw = new JSONWriter();
            jw.Array();

            for (int j = 0; j < s.Patterns.Count; j++)
            {
                Pattern p = s.Patterns[j];

                jw.Class();

                jw.Field("id", p.ID);
                jw.Field("instrument", p.InstrumentID);
                jw.Field("name", p.Name);
                jw.Field("duration", p.Duration);

                jw.Array("notes");
                for (int k = 0; k < p.Notes.Count; k++)
                {
                    PatternNote pn = p.Notes[k];
                    jw.Class();
                    jw.Field("id", pn.ID);
                    jw.Field("from", pn.From);
                    jw.Field("to", pn.To);
                    jw.Field("note", pn.Note);
                    jw.Field("velocity", pn.Velocity);
                    jw.End();
                }
                jw.End();

                jw.Array("automations");
                for (int k = 0; k < p.Automations.Count; k++)
                {
                    PatternAutomation pa = p.Automations[k];
                    jw.Class();
                    jw.Field("id", pa.ID);
                    jw.Field("macro", pa.Macro);
                    jw.Field("channel", pa.Channel);
                    jw.Array("keys");
                    for (int u = 0; u < pa.Keys.Count; u++)
                    {
                        jw.Class();
                        jw.Field("id", pa.Keys[u].ID);
                        jw.Field("time", pa.Keys[u].Time);
                        jw.Field("value", pa.Keys[u].Value);
                        jw.End();
                    }
                    jw.End();
                    jw.End();
                }
                jw.End();

                jw.End();
            }

            jw.End();

            context.Response.Write("g_Patterns = ");
            context.Response.Write(jw.ToString(JSONFormatting.Pretty));
            context.Response.Write(";\n");
        }
Esempio n. 40
0
        private static void WriteValue(JSONWriter writer, object obj)
        {
            if (obj == null)
                writer.WriteNull();

            if (obj is System.String)
                writer.WriteValue((string) obj);

            if (obj is System.Boolean)
                writer.WriteValue((bool) obj);

            if (obj is System.Double)
                writer.WriteValue(Convert.ToDouble(obj));

            if (obj is System.Int32)
                writer.WriteValue(Convert.ToInt32(obj));

            if (obj is System.Int64)
                writer.WriteValue(Convert.ToInt64(obj));

            if (obj is ArrayList) {
                writer.WriteStartArray();

                foreach (object val in ((ArrayList) obj))
                    WriteValue(writer, val);

                writer.WriteEndArray();
            }

            if (obj is NameValueCollection) {
                writer.WriteStartObject();

                string[] keys = GetReversedKeys(obj);
                foreach (string key in keys) {
                    writer.WritePropertyName(key);
                    WriteValue(writer, ((NameValueCollection) obj)[key]);
                }

                writer.WriteEndObject();
            }

            if (obj is Hashtable) {
                writer.WriteStartObject();

                string[] keys = GetReversedKeys(obj);
                foreach (string key in keys) {
                    writer.WritePropertyName((string) key);
                    WriteValue(writer, ((Hashtable) obj)[key]);
                }

                writer.WriteEndObject();
            }
        }
Esempio n. 41
0
        private void GetTrackList(WebContext context)
        {
            string sid = context.Request.GetParameter("gettracklist");
            Song s = State.CurrentSong;
            JSONWriter jw = new JSONWriter();
            jw.Class();
            jw.Array("tracks");
            for (int k = 0; k < s.Tracks.Count; k++)
            {
                SongTrack tr = s.Tracks[k];
                //	if (tr.ID == insid)
                {
                    jw.Class();
                    jw.Field("id", tr.ID);
                    jw.Field("name", tr.Name);

                    if (tr.CurrentPatternID != null)
                        jw.Field("pattern", tr.CurrentPatternID);
                    else
                        jw.Field("pattern", "");

                    if (tr.CuedPatternID != null)
                        jw.Field("cued", tr.CuedPatternID);
                    else
                        jw.Field("cued", "");

                    jw.Field("volume", tr.Volume);
                    jw.Field("transpose", tr.Transpose);
                    jw.Field("mute", tr.Muted ? 1 : 0);
                    jw.Field("solo", tr.Solo ? 1 : 0);
                    jw.End();
                    //					jw.Field("type", ins.Type);
                    //					jw.Field("mididevice", ins.MidiDevice);
                    //					jw.Field("midichannel", ins.MidiChannel);
                    //					jw.Field("midipatch", ins.MidiPatch);
                }
            }
            jw.End();
            jw.End();
            context.Response.ContentType = "text/javascript";
            context.Response.Write(jw.ToString());
        }
Esempio n. 42
0
        private static void ListSongJSON(WebContext context, Song s)
        {
            JSONWriter jw = new JSONWriter();
            jw.Class();
            jw.Field("bpm", s.BPM);
            jw.Field("beats1", s.Beats1);
            jw.Field("beats2", s.Beats2);
            jw.End();

            context.Response.Write("g_Song = ");
            context.Response.Write(jw.ToString(JSONFormatting.Pretty));
            context.Response.Write(";\n");
        }
Esempio n. 43
0
        private static void ListMidiDevicesJSON(WebContext context, Song s)
        {
            JSONWriter jw = new JSONWriter();
            jw.Array();

            List<int> ids = MidiWrapper.GetDeviceIDs();

            for (int k = 0; k < ids.Count; k++)
            {
                string nam = MidiWrapper.GetDeviceName(ids[k]);
                jw.Class();
                jw.Field("id", ids[k]);
                jw.Field("name", nam);
                jw.End();
            }

            jw.End();

            context.Response.Write("g_MidiDevices = ");
            context.Response.Write(jw.ToString(JSONFormatting.Pretty));
            context.Response.Write(";\n");
        }
Esempio n. 44
0
 private void GetAutomationChannels(WebContext context)
 {
     JSONWriter jw = new JSONWriter();
     jw.Class();
     jw.Array("channels");
     for (int k = 0; k < 127; k++)
     {
         jw.Class();
         jw.Field("id", k);
         jw.Field("name", "Automation channel " + k);
         jw.End();
     }
     jw.End();
     jw.End();
     context.Response.ContentType = "text/javascript";
     context.Response.Write(jw.ToString());
 }
Esempio n. 45
0
        // Algorithm parameters

        //"HS256",	"http://www.w3.org/2001/04/xmldsig-more#hmac-sha256",	    "HmacSHA256",	        "1.2.840.113549.2.9"
        //"HS384",	"http://www.w3.org/2001/04/xmldsig-more#hmac-sha384",	    "HmacSHA384",	        "1.2.840.113549.2.10"
        //"HS512",	"http://www.w3.org/2001/04/xmldsig-more#hmac-sha512",	    "HmacSHA512",	        "1.2.840.113549.2.11"
        //"RS256",	"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",	    "SHA256withRSA",	    "1.2.840.113549.1.1.11"
        //"RS384",	"http://www.w3.org/2001/04/xmldsig-more#rsa-sha384",	    "SHA384withRSA",	    "1.2.840.113549.1.1.12"
        //"RS512",	"http://www.w3.org/2001/04/xmldsig-more#rsa-sha512",	    "SHA512withRSA",	    "1.2.840.113549.1.1.13"
        //"ES256",	"http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256",	    "SHA256withECDSA",	    "1.2.840.10045.4.3.2"
        //"ES384",	"http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384",	    "SHA384withECDSA",	    "1.2.840.10045.4.3.3"
        //"ES512",	"http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha512",	    "SHA512withECDSA",	    "1.2.840.10045.4.3.4"
        //"PS256",	"http://www.w3.org/2007/05/xmldsig-more#sha256-rsa-MGF1",	"SHA256withRSAandMGF1",	"1.2.840.113549.1.1.10"
        //"PS384",	"http://www.w3.org/2007/05/xmldsig-more#sha384-rsa-MGF1",	"SHA384withRSAandMGF1",	"1.2.840.113549.1.1.10"
        //"PS512",	"http://www.w3.org/2007/05/xmldsig-more#sha512-rsa-MGF1",	"SHA512withRSAandMGF1",	"1.2.840.113549.1.1.10"

        // Content encryption modes

        //"A128CBC-HS256",	"	http://www.w3.org/2001/04/xmlenc#aes128-cbc",	"	AES/CBC/PKCS5Padding",	"	2.16.840.1.101.3.4.1.2
        //"A192CBC-HS384",	"	http://www.w3.org/2001/04/xmlenc#aes192-cbc",	"	AES/CBC/PKCS5Padding",	"	2.16.840.1.101.3.4.1.22
        //"A256CBC-HS512",	"	http://www.w3.org/2001/04/xmlenc#aes256-cbc",	"	AES/CBC/PKCS5Padding",	"	2.16.840.1.101.3.4.1.42
        //"A128GCM",	"	http://www.w3.org/2009/xmlenc11#aes128-gcm",	"	AES/GCM/NoPadding",	"	2.16.840.1.101.3.4.1.6
        //"A192GCM",	"	http://www.w3.org/2009/xmlenc11#aes192-gcm",	"	AES/GCM/NoPadding",	"	2.16.840.1.101.3.4.1.26
        //"A256GCM",	"	http://www.w3.org/2009/xmlenc11#aes256-gcm",	"	AES/GCM/NoPadding",	"	2.16.840.1.101.3.4.1.46


        // Key wrapping modes

        /// <summary>
        /// Encode object as a JSON byte array.
        /// </summary>
        /// <returns>The encoded data.</returns>
        public byte[] ToJson() {
            var JSONWriter = new JSONWriter();
            Serialize(JSONWriter);
            return JSONWriter.GetBytes;
            }
Esempio n. 46
0
 public override string ToString()
 {
     StringWriter _Writer = new StringWriter ();
     JSONWriter _JSONWriter = new JSONWriter (_Writer);
     Serialize (_JSONWriter, true);
     return _Writer.ToString ();
 }
Esempio n. 47
0
        private void GetInstrumentList(WebContext context)
        {
            Song s = State.CurrentSong;
            JSONWriter jw = new JSONWriter();
            jw.Class();
            jw.Array("instruments");
            for (int k = 0; k < s.Instruments.Count; k++)
            {
                Instrument ins = s.Instruments[k];

                jw.Class();
                jw.Field("id", ins.ID);
                jw.Field("name", ins.Name);
                jw.Field("type", ins.Type);
                jw.End();
            }
            jw.End();
            jw.End();
            context.Response.ContentType = "text/javascript";
            context.Response.Write(jw.ToString());
        }
Esempio n. 48
0
        public ActionResult Users(string method, string id)
        {
            string token = Request["token"];
            string userid = APITokens.GetUserID(token);

            if (method == "get")
            {

            }
            else if (method == "list")
            {

                JSONWriter jw = new JSONWriter();
                jw.Class();
                jw.Array("users");

                DBDataContext db = new DBDataContext();

                var users = from u in db.Users orderby u.UserName ascending select u;
                //	if (computerid != 0)
                //		vols = from v in vols where v.ComputerID.Equals(computerid) select v;

                foreach (Users u in users)
                {
                    jw.Class();
                    jw.Field("id", u.UserID.ToString());
                    jw.Field("name", u.UserName);
                    jw.End();
                }

                jw.End();
                jw.End();

                return new JSONResponseResult(jw.ToString(JSONFormatting.Pretty));

            }
            else if (method == "add")
            {
                if (string.IsNullOrEmpty(userid))
                    return new JSONResponseResult("not authenticated");

            }
            else if (method == "remove")
            {
                if (string.IsNullOrEmpty(userid))
                    return new JSONResponseResult("not authenticated");
            }

            return new JSONResponseResult("unknown users-command; method=" + method + ", id=" + id);
        }
Esempio n. 49
0
        public ActionResult Volumes(string method, string id)
        {
            string token = Request["token"];
            string userid = APITokens.GetUserID(token);

            if (method == "get")
            {
                return new JSONResponseResult("ok");
            }
            else if (method == "list")
            {
                int computerid = 0;
                if (!string.IsNullOrEmpty(Request["token"]))
                    int.TryParse(Request["token"], out computerid);

                JSONWriter jw = new JSONWriter();
                jw.Class();
                jw.Array("volumes");

                DBDataContext db = new DBDataContext();

                var vols = from v in db.Volumes select v;

                if (computerid != 0)
                    vols = from v in vols where v.ComputerID.Equals(computerid) select v;

                foreach (Volume v in vols)
                {
                    jw.Class();
                    jw.Field("id", v.ID);
                    jw.Field("name", v.VolumeName);
                    if (v.Computers != null)
                    {
                        jw.Field("computerid", v.Computers.ID);
                        jw.Field("computername", v.Computers.ComputerName);
                    }
                    jw.End();
                }

                jw.End();
                jw.End();

                return new JSONResponseResult(jw.ToString(JSONFormatting.Pretty));
            }
            else if (method == "add")
            {
                if (string.IsNullOrEmpty(userid))
                    return new JSONResponseResult("not authenticated");

                int compid = 0;
                int.TryParse(Request["computer"], out compid);

                int ds = 0;
                int.TryParse(Request["disksize"], out ds);

                int du = 0;
                int.TryParse(Request["diskused"], out du);

                DBDataContext db = new DBDataContext();

                Volume v = new Volume();
                v.ComputerID = compid;
                v.CreatedDate = DateTime.Now;

                db.Volumes.InsertOnSubmit(v);
                db.SubmitChanges();

                return new JSONResponseResult("{ status:'ok', id:'" + v.ID + "' }");
            }
            else if (method == "remove")
            {
                if (string.IsNullOrEmpty(userid))
                    return new JSONResponseResult("not authenticated");
            }

            return new JSONResponseResult("unknown volumes-command; method=" + method + ", id=" + id);
        }
Esempio n. 50
0
        private static void ListTracksJSON(WebContext context, Song s)
        {
            JSONWriter jw = new JSONWriter();
            jw.Array();

            for (int j = 0; j < s.Tracks.Count; j++)
            {
                SongTrack st = s.Tracks[j];
                jw.Class();
                jw.Field("id", st.ID);
                jw.Field("name", st.Name);

                if (st.CurrentPatternID != null)
                    jw.Field("pattern", st.CurrentPatternID);
                else
                    jw.Field("pattern", "");

                if (st.CuedPatternID != null)
                    jw.Field("cued", st.CuedPatternID);
                else
                    jw.Field("cued", "");

                jw.Field("volume", st.Volume);
                jw.Field("transpose", st.Transpose);
                jw.Field("mute", st.Muted ? 1 : 0);
                jw.Field("solo", st.Solo ? 1 : 0);
                jw.End();
            }

            jw.End();

            context.Response.Write("g_Tracks = ");
            context.Response.Write(jw.ToString(JSONFormatting.Pretty));
            context.Response.Write(";\n");
        }
Esempio n. 51
0
        /// <summary>
        /// 
        /// </summary>
        public static void SerializeRPC(string id, object error, object obj, Stream stream)
        {
            JSONWriter writer = new JSONWriter(new StreamWriter(stream));

            // Start JSON output
            writer.WriteStartObject();
            writer.WritePropertyName("result");

            // Serialize result set
            if (obj is Moxiecode.Manager.Utils.ResultSet) {
                ResultSet rs = (ResultSet) obj;

                writer.WriteStartObject();

                // Write header
                writer.WritePropertyName("header");
                writer.WriteStartObject();

                foreach (string key in rs.Header.Keys) {
                    writer.WritePropertyName(key);
                    writer.WriteValue(rs.Header[key]);
                }

                writer.WriteEndObject();

                // Write columns
                writer.WritePropertyName("columns");
                writer.WriteStartArray();

                foreach (string col in rs.Columns)
                    writer.WriteValue(col);

                writer.WriteEndArray();

                // Write data
                writer.WritePropertyName("data");
                writer.WriteStartArray();

                foreach (ArrayList row in rs.Data) {
                    writer.WriteStartArray();

                    foreach (object item in row)
                        WriteValue(writer, item);

                    writer.WriteEndArray();
                }

                writer.WriteEndArray();

                // Write config
                if (rs.Config != null) {
                    writer.WritePropertyName("config");
                    writer.WriteStartObject();

                    foreach (string key in rs.Config.AllKeys) {
                        writer.WritePropertyName(key);
                        writer.WriteValue(rs.Config[key]);
                    }

                    writer.WriteEndObject();
                }

                // End result
                writer.WriteEndObject();
            } else
                WriteValue(writer, obj);

            // Write id
            writer.WritePropertyName("id");
            writer.WriteValue(id);

            // Write error
            writer.WritePropertyName("error");
            writer.WriteValue(null);

            // Close
            writer.WriteEndObject();
            writer.Close();
        }
Esempio n. 52
0
 public static void ReturnJSON(JSONWriter jw)
 {
     ReturnJavascript(jw.ToString(JSONFormatting.Pretty));
 }
Esempio n. 53
0
        private void GetTiming(WebContext context)
        {
            // throw new NotImplementedException();

            string sid = context.Request.GetParameter("gettiming");

            Song s = State.CurrentSong;

            JSONWriter jw = new JSONWriter();
            jw.Class();
            jw.Field("bpm", s.BPM);
            jw.Field("measure1", s.Beats1);
            jw.Field("measure2", s.Beats2);
            jw.End();

            context.Response.ContentType = "text/javascript";
            context.Response.Write(jw.ToString());
        }
Esempio n. 54
0
        public ActionResult Measures(string method, string id)
        {
            string token = Request["token"];
            string userid = APITokens.GetUserID(token);

            if (method == "get")
            {

            }
            else if (method == "list")
            {
                int volumeid = 0;
                if (!string.IsNullOrEmpty(Request["volume"]))
                    int.TryParse(Request["volume"], out volumeid);

                JSONWriter jw = new JSONWriter();
                jw.Class();
                jw.Array("measurements");

                DBDataContext db = new DBDataContext();

                var measurements = from m in db.Measures select m;
                if (volumeid != 0)
                    measurements = from m in measurements where m.VolumeID.Equals(volumeid) select m;

                measurements = from m in measurements orderby m.MeasureDate descending select m;

                foreach (Measure m in measurements)
                {
                    jw.Class();
                    jw.Field("id", m.ID);
                    if (m.MeasureDate.HasValue)
                        jw.Field("date", m.MeasureDate.Value.ToString("R"));
                    jw.Field("size", m.MeasureSize.ToString());
                    jw.Field("used", m.MeasureUsed.ToString());
                    jw.End();
                }

                jw.End();
                jw.End();

                return new JSONResponseResult(jw.ToString(JSONFormatting.Pretty));

            }
            else if (method == "add")
            {
                if (string.IsNullOrEmpty(userid))
                    return new JSONResponseResult("not authenticated");

                string un = Request["username"];

                // int compid = 0;
                // int.TryParse(Request["computer"], out compid);

                int volid = 0;
                int.TryParse(Request["volume"], out volid);

                int ds = 0;
                int.TryParse(Request["disksize"], out ds);

                int du = 0;
                int.TryParse(Request["diskused"], out du);

                DBDataContext db = new DBDataContext();

                var user = from u in db.Users where u.UserName.Equals(un) select u;
                if (user != null)
                {

                    Measure m = new Measure();

                    m.MeasureSize = ds;
                    m.MeasureUsed = du;
                    m.VolumeID = volid;
                    m.MeasureDate = DateTime.Now;

                    db.Measures.InsertOnSubmit(m);
                    db.SubmitChanges();

                    return new JSONResponseResult("ok");
                }
            }
            else if (method == "remove")
            {
                if (string.IsNullOrEmpty(userid))
                    return new JSONResponseResult("not authenticated");

            }

            return new JSONResponseResult("unknown measures-command; method=" + method + ", id=" + id);
        }