Example #1
0
        public static HttpContent json(HttpRequest request)
        {
            try
            {
                var result = new Dictionary<string, object>();
                result.Add("request", Encoding.ASCII.GetString(request.Data));
                result.Add("guid", Guid.NewGuid().ToString());
                result.Add("html", @"<h1 class=""page-header"">" + request.Data + @"</h1><br/>" );

                if (Encoding.ASCII.GetString(request.Data) == "error") throw new ApplicationException("error test");

                return new HttpContent(result.ToJSON());
            }
            catch (Exception ex)
            {
                return new HttpErrorContent(ex);
            }
        }
Example #2
0
        public static string BuildSemantics(IDictionary<string, object> semantics)
        {
            var strings = new Dictionary<string, string>();
            foreach (var entry in semantics)
            {
                if (entry.Value == null)
                    continue;
                var type = entry.Value.GetType();
                if (type == typeof(string))
                    strings.Add(entry.Key, entry.Value as string);
#if NETFX
                else if (type.IsEnum)
#elif UNIVERSAL
                else if (type.GetTypeInfo().IsEnum)
#endif
                    strings.Add(entry.Key, ((int)entry.Value).ToStringInvariant());
                else if (type.IsNumber())
                    strings.Add(entry.Key, entry.ToStringInvariant());
                else
                    strings.Add(entry.Key, entry.Value.ToJSON());
            }
            return strings.ToJSON(HtmlEncode: false);
        }
Example #3
0
        static void Main(string[] args)
        {
            string a = "hello", b = "bye";
            Console.WriteLine(a.GreaterThan(b));

            int[] array = { 1, 2, 3, 4 };
            Console.WriteLine(array.Implode());
            Console.WriteLine(array.ToJSON());

            List<int> list = new List<int>() { 5, 6, 7, 8 };
            Console.WriteLine(list.Implode());
            Console.WriteLine(list.ToJSON());

            Dictionary<int, string> dict = new Dictionary<int, string>();
            dict.Add(3, "three");
            dict.Add(5, "five");
            Console.WriteLine(dict.ToJSON());

            TestClass test = new TestClass("Andrew", new int[] { 1, 2, 3 }, 13);
            Console.WriteLine(test.ToJSON());

            Console.ReadKey();
        }
Example #4
0
 public string LastSnapshotId()
 {
     Dictionary<String, Guid> result = new Dictionary<string, Guid>();
     result.Add(RESULT, ServerContextSingleton.Instance.ServerContext.LastSnapshotId());
     return result.ToJSON();
 }
Example #5
0
        public string GetRootType()
        {
            Type rootType = ServerContextSingleton.Instance.ServerContext.GetRootType();

            TypeMetadata root = TypeSingleton.ExtractTypeMetadata(rootType);

            Dictionary<String, TypeMetadata> result = new Dictionary<string, TypeMetadata>();
            result.Add(RESULT, root);
            return result.ToJSON();
        }
Example #6
0
 public string GetRootObjectId(string snapshotId)
 {
     Guid snapshotIdParsed = Guid.Parse(snapshotId);
     Guid rootId = ServerContextSingleton.Instance.ServerContext.GetRootObjectId(snapshotIdParsed);
     Dictionary<String, Guid> result = new Dictionary<string, Guid>();
     result.Add(RESULT, rootId);
     return result.ToJSON();
 }
Example #7
0
 public string GetNode(string nodeId, int access)
 {
     Guid nodeGuid = Guid.Parse(nodeId);
     NodeAccess nodeAccess = (NodeAccess)access;
     Dictionary<String, NodeWrapper> result = new Dictionary<string, NodeWrapper>();
     var node = ServerContextSingleton.Instance.ServerContext.GetNode(nodeGuid, nodeAccess);
     var nodeWraped = NodeWrapper.TransformeNode(node);
     result.Add(RESULT, nodeWraped);
     return result.ToJSON();
 }
Example #8
0
 public string EnumerateNodes()
 {
     Dictionary<String, System.Collections.IEnumerable> result = new Dictionary<string, System.Collections.IEnumerable>();
     result.Add(RESULT, ServerContextSingleton.Instance.ServerContext.EnumerateNodes());
     return result.ToJSON();
 }
Example #9
0
 public string DefaultWorkspaceTimeout()
 {
     Dictionary<String, long> result = new Dictionary<string, long>();
     result.Add(RESULT, ServerContextSingleton.Instance.ServerContext.DefaultWorkspaceTimeout.Ticks);
     return result.ToJSON();
 }
Example #10
0
        public string Contains(string identifier)
        {
            Guid id = Guid.Parse(identifier);

            Dictionary<String, Boolean> result = new Dictionary<string, Boolean>();
            result.Add(RESULT, ServerContextSingleton.Instance.ServerContext.Contains(id));
            return result.ToJSON();
        }
Example #11
0
        public string Commit(string workspaceId, object changeSet)
        {
            Guid guidWorkspaceId = Guid.Parse(workspaceId);
            //transform changeSet into IsolatedChangeSet object
            IsolatedChangeSet<Guid, object, EdgeData> serverChangeSet = ChangeSetParser.Parse(changeSet);
            //commit changes
            CommitResult<Guid> commitResult =
                ServerContextSingleton.Instance.ServerContext.Commit(guidWorkspaceId, serverChangeSet);

            String resultSnapshotId = commitResult.ResultSnapshotId.ToString();
            Dictionary<string, string> mapping = new Dictionary<string, string>();
            foreach (KeyValuePair<Guid, Guid> mapObject in commitResult.Mapping)
            {
                mapping.Add(mapObject.Key.ToString(), mapObject.Value.ToString());
            }

            CommitResult<String> commitResultString = new CommitResult<string>(resultSnapshotId, mapping);

            Dictionary<String, CommitResult<String>> rez = new Dictionary<string, CommitResult<string>>();
            rez.Add(RESULT, commitResultString);
            return rez.ToJSON();
        }
Example #12
0
        void Button6Click(object sender, EventArgs e)
        {
            var data = @"\tC:\\test\\ \n";

            data = Regex.Replace(data, @"([^\\]|^)([\\][n])", m => m.Groups[1].Value + "\n");
            data = Regex.Replace(data, @"([^\\]|^)([\\][t])", m => m.Groups[1].Value + "\t");
            data = Regex.Replace(data, @"([^\\]|^)([\\][\\])", m => m.Groups[1].Value + "\\");

            System.Diagnostics.Debug.WriteLine(data);

            var json = new Dictionary<string, object>();
            json.Add("test", @"c:\test\ 102/103 ""abc efg""");

            var jsonString = json.ToJSON();

            var decodeJsonString = jsonString.GetJSON("test", "abc");
            json = new Dictionary<string, object>();
            json.Add("test", decodeJsonString);

            var jsonString2 = json.ToJSON();

            System.Diagnostics.Debug.WriteLine(jsonString);
            System.Diagnostics.Debug.WriteLine(jsonString2);
        }
Example #13
0
        static bool WriteConfig()
        {
            try
            {
                var config = new Dictionary<Type, ThingConfig>();

                foreach (var kv in Lookup)
                {
                    var pinConf = kv.Key.Config.Find(cp => cp.Name == "Pin").Value;
                    var sensor = kv.Value;
                    config.Add(sensor.GetType(), new ThingConfig() { Pin = pinConf, Period = (int)sensor.Watcher.SamplingPeriod });
                }

                File.WriteAllText(ThingsConfFileName, config.ToJSON());
                return true;
            }
            catch (Exception ex)
            {
                DebugEx.TraceErrorException(ex);
                return false;
            }
        }
Example #14
0
        static Dictionary<Type, ThingConfig> ReadConfig()
        {
            Dictionary<Type, ThingConfig> config = null;
            try
            {
                if (File.Exists(ThingsConfFileName))
                {
                    var content = File.ReadAllText(ThingsConfFileName);
                    //deserialize into List of Configurations and pick the active one
                    config = content.FromJSON<Dictionary<Type, ThingConfig>>();
                }
            }
            catch (Exception ex)
            {
                DebugEx.TraceErrorException(ex);
            }

            if (config == null)
            {
                config = new Dictionary<Type, ThingConfig>()
                    {
                        { typeof(GPIO),              new ThingConfig() { Pin = "",    Period = 100  } },
                        { typeof(Buzzer),            new ThingConfig() { Pin = "D7",  Period = 0    } },
                        { typeof(RgbLed),            new ThingConfig() { Pin = "D4",  Period = 0    } },
                        { typeof(SoundSensor),       new ThingConfig() { Pin = "A2",  Period = 1000 } },
                        { typeof(LightSensor),       new ThingConfig() { Pin = "A1",  Period = 500  } },
                        { typeof(Button),            new ThingConfig() { Pin = "D2",  Period = 200  } },
                        { typeof(RotaryAngleSensor), new ThingConfig() { Pin = "A0",  Period = 200  } },
                        { typeof(Relay),             new ThingConfig() { Pin = "D3",  Period = 1000 } },
                        { typeof(TempAndHumidity),   new ThingConfig() { Pin = "D6",  Period = 500  } },
                        { typeof(UltraSonicRanger),  new ThingConfig() { Pin = "D8",  Period = 100  } },
                        { typeof(LCD),               new ThingConfig() { Pin = "I2C", Period = 0    } },
                    };

                try
                {
                    File.WriteAllText(ThingsConfFileName, config.ToJSON());
                }
                catch (Exception ex) { DebugEx.TraceErrorException(ex); }
            }
            return config;
        }
Example #15
0
 public string SnapshotIsolationEnabled()
 {
     Dictionary<String, Boolean> result = new Dictionary<string, Boolean>();
     result.Add(RESULT, ServerContextSingleton.Instance.ServerContext.SnapshotIsolationEnabled);
     return result.ToJSON();
 }
Example #16
0
        public string CreateSubscription(Guid workspaceId, Guid instanceId, string propertyName, bool notifyChangesFromSameWorkspace, string callerId)
        {
            //EventHandler<Execom.IOG.Events.ObjectChangedEventArgs> delegate +=
            Subscription sub = null;
            if(propertyName == null)
            {
                sub = ServerContextSingleton.Instance.ServerContext.CreateSubscription(workspaceId, instanceId, notifyChangesFromSameWorkspace, JSEventHandler);
                MemberManager.AddSubscription(callerId, sub.SubscriptionId.ToString());
            }
            else
            {
                sub = ServerContextSingleton.Instance.ServerContext.CreateSubscription(workspaceId, instanceId, propertyName, notifyChangesFromSameWorkspace, JSEventHandler);
                MemberManager.AddSubscription(callerId, sub.SubscriptionId.ToString());
            }

            Dictionary<String, Subscription> result = new Dictionary<String, Subscription>();
            result.Add(RESULT, sub);
            return result.ToJSON();
        }
Example #17
0
 public string ChangesBetween(string oldSnapshotId, string newSnapshotId)
 {
     Guid guidOldSnapshotId = Guid.Parse(oldSnapshotId);
     Guid guidNewSnapshotId = Guid.Parse(newSnapshotId);
     Dictionary<String, String> changes =
         ServerContextSingleton.Instance.ServerContext.ChangesBetween(guidOldSnapshotId, guidNewSnapshotId).
         ToDictionary(k => k.Key.ToString(), k => k.Value.ToString()); ;
     Dictionary<String, Dictionary<String, String>> rez = new Dictionary<string, Dictionary<String, String>>();
     rez.Add(RESULT, changes);
     return rez.ToJSON();
 }
Example #18
0
 public HttpContent(Dictionary<string, object> json)
     : this(Encoding.ASCII.GetBytes(json.ToJSON()), "application/json")
 {
 }