Example #1
0
        /// <summary>
        /// Обращение к подписке на события с файлом в сервисе редактирования
        /// </summary>
        /// <param name="documentTrackerUrl">Url to the command service</param>
        /// <param name="method">Name of method</param>
        /// <param name="documentRevisionId">Key for caching on service, whose used in editor</param>
        /// <param name="callbackUrl">Url to the callback handler</param>
        /// <param name="users">users id for drop</param>
        /// <param name="status">saving status</param>
        /// <param name="version">server version</param>
        /// <returns>Response</returns>
        public CommandResultTypes CommandRequest(
            string documentTrackerUrl,
            CommandMethod method,
            string documentRevisionId,
            string callbackUrl,
            string users,
            string status,
            out string version)
        {
            var validateKey = GenerateValidateKey(documentRevisionId, string.Empty);

            var urlDocumentService = documentTrackerUrl + RequestTrackParams;
            var urlToTrack         = String.Format(urlDocumentService,
                                                   method.ToString().ToLower(CultureInfo.InvariantCulture),
                                                   documentRevisionId,
                                                   validateKey,
                                                   HttpUtility.UrlEncode(callbackUrl ?? ""),
                                                   HttpUtility.UrlEncode(users ?? ""),
                                                   status);

            var request = (HttpWebRequest)WebRequest.Create(urlToTrack);

            request.Method = "GET";

            // hack. http://ubuntuforums.org/showthread.php?t=1841740
            if (WorkContext.IsMono)
            {
                ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
            }

            string data;

            using (var response = request.GetResponse())
                using (var stream = response.GetResponseStream())
                {
                    if (stream == null)
                    {
                        throw new Exception("Response is null");
                    }

                    using (var reader = new StreamReader(stream))
                    {
                        data = reader.ReadToEnd();
                    }
                }

            var jResponse = JObject.Parse(data);

            try
            {
                version = jResponse.Value <string>("version");
            }
            catch (Exception)
            {
                version = "0";
            }

            return((CommandResultTypes)jResponse.Value <int>("error"));
        }
        public static string SendCommand <T>(List <T> data, CommandMethod method, string modelData)
        {
            var          jdata = JsonConvert.SerializeObject(data);
            CommandModel cmd   = new CommandModel();

            cmd.Command = method.ToString();
            cmd.Model   = modelData;
            cmd.Data    = jdata;
            return(JsonConvert.SerializeObject(cmd));
        }