Ejemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Internal method for translating the specified text.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override string InternalTranslate(string srcText)
        {
            var text     = HttpUtilityFromMono.UrlPathEncode(srcText);
            var ver      = HttpUtilityFromMono.UrlEncode("1.0");
            var langPair = HttpUtilityFromMono.UrlEncode(string.Format("{0}|{1}", m_srcCultureId, m_tgtCultureId));
            var encodedRequestUrlFragment = string.Format("?v={0}&q={1}&langpair={2}", ver, text, langPair);

            try
            {
                var request  = WebRequest.Create(kServiceUrl + encodedRequestUrlFragment);
                var response = request.GetResponse();

                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    var json = reader.ReadLine();
                    using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(json)))
                    {
                        var ser         = new DataContractJsonSerializer(typeof(JSONResponse));
                        var translation = ser.ReadObject(ms) as JSONResponse;
                        reader.Close();
                        return(translation.responseData.translatedText);
                    }
                }
            }
            catch (Exception)
            {
                return(string.Empty);
            }
        }
Ejemplo n.º 2
0
        public virtual string GetSyncUri(ILfProject project)
        {
            var settings = MainClass.Container.Resolve <LfMergeSettings>();

            if (!string.IsNullOrEmpty(settings.LanguageDepotRepoUri))
            {
                return(settings.LanguageDepotRepoUri);
            }

            var uriBldr = new UriBuilder(project.LanguageDepotProjectUri)
            {
                UserName = Username,
                Password = Password,
                Path     = HttpUtilityFromMono.UrlEncode(project.LanguageDepotProject.Identifier)
            };

            return(uriBldr.Uri.ToString());
        }
Ejemplo n.º 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get a URL corresponding to this link
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents this instance.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public override string ToString()
        {
            UriBuilder uriBuilder = new UriBuilder(kSilScheme, kLocalHost);

            uriBuilder.Path = kLink;
            StringBuilder query = new StringBuilder();

            AddProperties(query);

            foreach (Property property in PropertyTableEntries)
            {
                query.AppendFormat("&{0}={1}", property.Name, Encode(property.Value));
            }

            //make it safe to represent as a url string (e.g., convert spaces)
            uriBuilder.Query = HttpUtilityFromMono.UrlEncode(query.ToString());

            return(uriBuilder.Uri.AbsoluteUri);
        }
Ejemplo n.º 4
0
        private void JumpToFlexObject(string url)
        {
            //// Flex expects the query to be UrlEncoded (I think so it can be used as a command line argument).
            var hostLength = url.IndexOf("?", StringComparison.InvariantCulture);

            if (hostLength < 0)
            {
                return;                 // can't do it, not a valid FLEx url.
            }
            var host = url.Substring(0, hostLength);
            // This should be fairly safe for a lift URL, since it won't have the "database=current" string in the query.
            // A lift URL will be something like:
            //		lift://foo.lift?type=entry&id=someguid&label=formforentry
            var originalQuery = url.Substring(hostLength + 1).Replace("database=current", "database=" + ProjectName);
            var query         = HttpUtilityFromMono.UrlEncode(originalQuery);

            // Instead of closing the conflict viewer we now need to fire this event to notify
            // the FLExConnectionHelper that we have a URL to jump to.
            if (JumpUrlChanged != null)
            {
                JumpUrlChanged(this, new JumpEventArgs(host + "?" + query));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This method receives the HtmlDetails stored in a conflict, and returns adjusted HTML.
        /// Specifically it fixes URLs containing "database=current" to contain the real project name,
        /// replaces WS identifiers with pretty names, and replaces reference property checksums
        /// with a nice list of reference properties that have conflicts (if any).
        /// </summary>
        internal string AdjustConflictHtml(string input)
        {
            var projectNameForUrl = HttpUtilityFromMono.UrlEncode(ProjectName);

            return(FixChecksums(FixWsRuns(input)).Replace(@"&amp;database=current&amp;", @"&amp;database=" + projectNameForUrl + @"&amp;"));
        }