コード例 #1
0
        public ActionResult <string> Get(string channelId, string resourceId, string instance)
        {
            try
            {
                // Just because .NET is some weird kind of monster and doesn't like to play well with URLs... Thanks Microsoft
                // Note WebUtility outputs stuff in a CORRECT fashion while HttpUtility is NOT suitable for case sensitive systems
                channelId  = WebUtility.UrlDecode(channelId);
                resourceId = WebUtility.UrlDecode(resourceId);
                instance   = WebUtility.UrlDecode(instance);

                // Check if the request was created by the current instance
                if (KeySync.instance.Equals(instance))
                {
                    // Sync all the calendars
                    KeySync.runCal();
                }
                // Clean up the current channel, it's not valid
                else
                {
                    GService.service.Channels.Stop(KeySync.deleteChannel(channelId, resourceId)).Execute();
                }
            }
            catch (Exception e)
            {
                ControlRoom.SendErrorMessage("Google Sync error", e.Message);
            }

            return(instance);
        }
コード例 #2
0
        private void Sync(KeySync ks)
        {
            ValueSyc vs;

            if (!_req.TryRemove(ks, out vs))
            {
                throw new Exception("attemping to sync non-existing request");
            }

            vs.done.Set();
        }
コード例 #3
0
        public void Put(DatastoreKey datastoreKey, T value)
        {
            var ks = new KeySync {
                op = PutKey, k = datastoreKey, value = value
            };
            ValueSyc vs;

            if (!Sync(ks, out vs))
            {
                _child.Put(datastoreKey, value);
                Sync(ks);
            }
        }
コード例 #4
0
        public void Delete(DatastoreKey datastoreKey)
        {
            var ks = new KeySync {
                op = DeleteKey, k = datastoreKey
            };
            ValueSyc vs;

            if (!Sync(ks, out vs))
            {
                _child.Delete(datastoreKey);
                Sync(ks);
            }
        }
コード例 #5
0
        public T Get(DatastoreKey datastoreKey)
        {
            var ks = new KeySync {
                op = GetKey, k = datastoreKey
            };
            ValueSyc vs;

            if (!Sync(ks, out vs))
            {
                vs.value = _child.Get(datastoreKey);
                Sync(ks);
            }
            return((T)vs.value);
        }
コード例 #6
0
 private bool Sync(KeySync ks, out ValueSyc vs)
 {
     if (!_req.TryGetValue(ks, out vs))
     {
         vs = new ValueSyc(done: new ManualResetEvent(false));
         _req.TryAdd(ks, vs);
         return(false);
     }
     else
     {
         vs.done.Set();
         return(true);
     }
 }
コード例 #7
0
        public bool Has(DatastoreKey datastoreKey)
        {
            var ks = new KeySync {
                op = HasKey, k = datastoreKey
            };
            ValueSyc vs;

            if (!Sync(ks, out vs))
            {
                vs.value = _child.Has(datastoreKey);
                Sync(ks);
            }
            return((bool)vs.value);
        }