Exemplo n.º 1
0
        internal ServerRequest(HttpServerRequest httpRequest, UrlData urlData, ServerRoute route)
        {
            _httpRequest = httpRequest;

            _urlData = urlData;
            _route = route;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Return to view the last object in the history. If the history is empty return to the home page.  
        /// </summary>
        public static MvcHtmlString CancelButton(this HtmlHelper html, object domainObject) {
            var fvm = domainObject as FindViewModel;

            if (fvm != null) {
                // if dialog return to target - unless it's a service 
                object target = fvm.ContextObject;
                domainObject = !PersistorUtils.CreateAdapter(target).Specification.IsService ? target : null;
            }

            // if target is transient  cancel back to history
            if (domainObject != null && PersistorUtils.CreateAdapter(domainObject).ResolveState.IsTransient()) {
                domainObject = null;
            }    

            string nextUrl = domainObject == null ? "" : html.Tab(html.ObjectTitle(domainObject).ToString(), IdHelper.ViewAction, domainObject).ToString();

            UrlData nextEntry;
            
            if (string.IsNullOrEmpty(nextUrl)) {
                List<string> existingUrls = html.ViewContext.HttpContext.Session.AllCachedUrls(ObjectCache.ObjectFlag.BreadCrumb).ToList();
                var existingEntries = existingUrls.Select(u => new UrlData(u)).ToArray();
                nextEntry = GetLastEntry(existingEntries);
            }
            else {
                nextEntry = new UrlData(nextUrl);
            }

            var cancelForm = new UrlData("");
            cancelForm.AddCancel(html, nextEntry);
     
            return MvcHtmlString.Create(cancelForm.ToString());
        }
Exemplo n.º 3
0
        private static UrlData GetNextEntry(UrlData[] entries, UrlData thisEntry) {
            if (entries.Count() == 1) {
                return UrlData.Empty();
            }
            if (entries.Last().Equals(thisEntry)) {
                // last in list so return one before 
                return entries[entries.Length - 2];
            }

            var previousEntry = UrlData.Empty();

            foreach (var entry in entries.Reverse()) {
                if (entry.Equals(thisEntry)) {
                    return previousEntry;
                }
                previousEntry = entry;
            }
            // not found - should never happen 
            return entries.Last();
        }
Exemplo n.º 4
0
 private static UrlData GetLastEntry(UrlData[] entries) {
     return entries.Any() ? entries.Last() : UrlData.Empty();
 }
Exemplo n.º 5
0
        public static MvcHtmlString TabbedHistory(this HtmlHelper html, int count, object domainObject = null) {
            List<string> existingUrls = html.ViewContext.HttpContext.Session.AllCachedUrls(ObjectCache.ObjectFlag.BreadCrumb).ToList();
            string newUrl = "";

            if (domainObject != null) {
                newUrl = html.Tab(html.ObjectTitle(domainObject).ToString(), IdHelper.ViewAction, domainObject).ToString();
                if (!(domainObject is FindViewModel) && !existingUrls.Contains(newUrl)) {
                    html.ViewContext.HttpContext.Session.AddOrUpdateInCache(domainObject, newUrl, ObjectCache.ObjectFlag.BreadCrumb);
                }
            }

            List<string> urls = html.ViewContext.HttpContext.Session.AllCachedUrls(ObjectCache.ObjectFlag.BreadCrumb).ToList();

            int sizeCache = urls.Count();
            int skip = sizeCache > count ? sizeCache - count : 0;

            urls = urls.Skip(skip).ToList();

            var tag = new TagBuilder("div");
            tag.AddCssClass(IdHelper.TabbedHistoryContainerName);

            UrlData[] entries = urls.Select(u => new UrlData(u)).ToArray();
            var newEntry = new UrlData(newUrl);

            foreach (UrlData currentEntry in entries) {
                
                if (currentEntry.Equals(newEntry)) {
                    currentEntry.SetActive();
                }

                UrlData nextEntry = GetNextEntry(entries, currentEntry);
                currentEntry.AddCloseThis(html, nextEntry);

                if (urls.Count > 1) {
                    currentEntry.AddCloseOthers(html);
                }

                currentEntry.AddCloseAll(html);
                tag.InnerHtml += currentEntry.ToString();
            }
            return MvcHtmlString.Create(tag.ToString());
        }
Exemplo n.º 6
0
 public void AddCancel(HtmlHelper html, UrlData nextEntry) {
     var cancel = html.ControllerAction(MvcUi.Cancel, IdHelper.CancelAction, IdHelper.HomeName, IdHelper.CancelButtonClass, MvcUi.Cancel, AddPageData(nextEntry, new RouteValueDictionary(new { nextId = nextEntry.Id }))).ToString();
     Document = XDocument.Parse(cancel).Element("form").Document;
 }
Exemplo n.º 7
0
 public void AddCloseThis(HtmlHelper html, UrlData nextEntry) {
     var closeThis = html.ControllerAction("", IdHelper.ClearHistoryItemAction, IdHelper.HomeName, IdHelper.ClearItemButtonClass, "", AddPageData(nextEntry, new RouteValueDictionary(new { id = Id, nextId = nextEntry.Id }))).ToString();
     var closeThisElem = XDocument.Parse(closeThis).Element("form");
     AddElement(closeThisElem);
 }
Exemplo n.º 8
0
            private static RouteValueDictionary AddPageData(UrlData entry, RouteValueDictionary rvd) {
                rvd.Add(IdHelper.PageKey, entry.Page);
                rvd.Add(IdHelper.PageSizeKey, entry.PageSize);
                rvd.Add(IdHelper.FormatKey, entry.Format);

                return rvd;
            }
Exemplo n.º 9
0
 /// <summary>
 /// get url with OCR data </summary>
 /// <param name="id"> string, id of task (e.g. from PostImage)</param>
 /// <param name="trials"> int, number of trials of receiving successful response</param>
 /// <returns> returns UrlData with URL (empty in case of failure) and Status of operation)</returns>
 public async Task<UrlData> GetOcr(string id, int trials)
 {
     var client = new HttpClient();
     UrlData resultUrl = new UrlData();
     setAuthentication(client);
     client.BaseAddress = new Uri("http://cloud.ocrsdk.com/getTaskStatus?taskId=" + id);
       try
       {
           for(int i = 0; i < trials; i++)
           {
             var response = await client.GetAsync(client.BaseAddress);
             response.EnsureSuccessStatusCode();
             var result = await response.Content.ReadAsStringAsync();
             XmlDocument doc = new XmlDocument();
             doc.LoadXml(result);
             var status = doc.SelectSingleNode("/response/task/@status").Value;
             if (status == "Completed")
               {
                 resultUrl.Url = doc.SelectSingleNode("/response/task/@resultUrl").Value;
                 resultUrl.Url = resultUrl.Url.Remove(4, 1);
                 resultUrl.Status = status;
                 break;
               }
               else if (status == "Queued" || status == "InProgess")
               {
                 System.Threading.Thread.Sleep(2000);
                 resultUrl.Url = "";
                 resultUrl.Status = status;
               }
               else
               {
                 resultUrl.Url = "";
                 resultUrl.Status = "Error";
               }
           }
       }
       catch (Exception exception)
       {
         //Console.WriteLine("CAUGHT EXCEPTION:");
         //Console.WriteLine(exception);
         resultUrl.Url = "";
         resultUrl.Status = "Error";
         return resultUrl;
       }
     return resultUrl;
 }
Exemplo n.º 10
0
 public override WebRequestHeaders GetUrlContent()
 {
     UrlData.Add(new WebRequestHeader("num-items", NumberOfItems.ToString()));
     UrlData.Add(new WebRequestHeader("tabs", Tabs.ToString()));
     return(base.GetUrlContent());
 }
Exemplo n.º 11
0
        protected UrlData newMediaObjectLogic(
            string blogid,
            string username,
            string password,
            FileData file)
        {
            if (validateUser(username, password))
            {
                User    u           = new User(username);
                Channel userChannel = new Channel(username);
                UrlData fileUrl     = new UrlData();
                if (userChannel.ImageSupport)
                {
                    Media rootNode;
                    if (userChannel.MediaFolder > 0)
                    {
                        rootNode = new Media(userChannel.MediaFolder);
                    }
                    else
                    {
                        rootNode = new Media(u.StartMediaId);
                    }

                    // Create new media
                    Media m = Media.MakeNew(file.name, MediaType.GetByAlias(userChannel.MediaTypeAlias), u, rootNode.Id);

                    Property fileObject = m.getProperty(userChannel.MediaTypeFileProperty);

                    var filename         = file.name.Replace("/", "_");
                    var relativeFilePath = _fs.GetRelativePath(fileObject.Id, filename);

                    fileObject.Value = _fs.GetUrl(relativeFilePath);
                    fileUrl.url      = fileObject.Value.ToString();

                    if (!fileUrl.url.StartsWith("http"))
                    {
                        var protocol = GlobalSettings.UseSSL ? "https" : "http";
                        fileUrl.url = protocol + "://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + fileUrl.url;
                    }

                    _fs.AddFile(relativeFilePath, new MemoryStream(file.bits));

                    // Try updating standard file values
                    try
                    {
                        string orgExt = "";
                        // Size
                        if (m.getProperty("umbracoBytes") != null)
                        {
                            m.getProperty("umbracoBytes").Value = file.bits.Length;
                        }
                        // Extension
                        if (m.getProperty("umbracoExtension") != null)
                        {
                            orgExt =
                                ((string)
                                 file.name.Substring(file.name.LastIndexOf(".") + 1,
                                                     file.name.Length - file.name.LastIndexOf(".") - 1));
                            m.getProperty("umbracoExtension").Value = orgExt.ToLower();
                        }
                        // Width and Height
                        // Check if image and then get sizes, make thumb and update database
                        if (m.getProperty("umbracoWidth") != null && m.getProperty("umbracoHeight") != null &&
                            ",jpeg,jpg,gif,bmp,png,tiff,tif,".IndexOf("," + orgExt.ToLower() + ",") > 0)
                        {
                            int fileWidth;
                            int fileHeight;

                            var stream = _fs.OpenFile(relativeFilePath);

                            Image image = Image.FromStream(stream);
                            fileWidth  = image.Width;
                            fileHeight = image.Height;
                            stream.Close();
                            try
                            {
                                m.getProperty("umbracoWidth").Value  = fileWidth.ToString();
                                m.getProperty("umbracoHeight").Value = fileHeight.ToString();
                            }
                            catch
                            {
                            }
                        }
                    }
                    catch
                    {
                    }

                    return(fileUrl);
                }
                else
                {
                    throw new ArgumentException(
                              "Image Support is turned off in this channel. Modify channel settings in umbraco to enable image support.");
                }
            }
            return(new UrlData());
        }
Exemplo n.º 12
0
 public override WebRequestHeaders GetUrlContent()
 {
     UrlData.Add(new WebRequestHeader("updated-min", UpdatedMin));
     UrlData.Add(new WebRequestHeader("new-results-expected", NewResultsExpected.ToString().ToLower()));
     return(base.GetUrlContent());
 }
Exemplo n.º 13
0
        protected UrlData newMediaObjectLogic(
            string blogid,
            string username,
            string password,
            FileData file)
        {
            if (validateUser(username, password))
            {
                User    u           = new User(username);
                Channel userChannel = new Channel(username);
                UrlData fileUrl     = new UrlData();
                if (userChannel.ImageSupport)
                {
                    Media rootNode;
                    if (userChannel.MediaFolder > 0)
                    {
                        rootNode = new Media(userChannel.MediaFolder);
                    }
                    else
                    {
                        rootNode = new Media(u.StartMediaId);
                    }

                    // Create new media
                    Media m = Media.MakeNew(file.name, MediaType.GetByAlias(userChannel.MediaTypeAlias), u, rootNode.Id);

                    Property fileObject = m.getProperty(userChannel.MediaTypeFileProperty);
                    string   _fullFilePath;
                    string   filename = file.name.Replace("/", "_");
                    // Generate file
                    if (UmbracoSettings.UploadAllowDirectories)
                    {
                        // Create a new folder in the /media folder with the name /media/propertyid
                        Directory.CreateDirectory(IOHelper.MapPath(SystemDirectories.Media + "/" + fileObject.Id));

                        _fullFilePath    = IOHelper.MapPath(SystemDirectories.Media + "/" + fileObject.Id + "/" + filename);
                        fileObject.Value = SystemDirectories.Media + "/" + fileObject.Id + "/" + filename;
                    }
                    else
                    {
                        filename         = fileObject.Id + "-" + filename;
                        _fullFilePath    = IOHelper.MapPath(SystemDirectories.Media + "/" + filename);
                        fileObject.Value = SystemDirectories.Media + "/" + filename;
                    }

                    string protocol = GlobalSettings.UseSSL ? "https" : "http";
                    fileUrl.url = protocol + "://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + IOHelper.ResolveUrl(fileObject.Value.ToString());

                    File.WriteAllBytes(_fullFilePath, file.bits);

                    // Try updating standard file values
                    try
                    {
                        string orgExt = "";
                        // Size
                        if (m.getProperty("umbracoBytes") != null)
                        {
                            m.getProperty("umbracoBytes").Value = file.bits.Length;
                        }
                        // Extension
                        if (m.getProperty("umbracoExtension") != null)
                        {
                            orgExt =
                                ((string)
                                 file.name.Substring(file.name.LastIndexOf(".") + 1,
                                                     file.name.Length - file.name.LastIndexOf(".") - 1));
                            m.getProperty("umbracoExtension").Value = orgExt.ToLower();
                        }
                        // Width and Height
                        // Check if image and then get sizes, make thumb and update database
                        if (m.getProperty("umbracoWidth") != null && m.getProperty("umbracoHeight") != null &&
                            ",jpeg,jpg,gif,bmp,png,tiff,tif,".IndexOf("," + orgExt.ToLower() + ",") > 0)
                        {
                            int fileWidth;
                            int fileHeight;

                            FileStream fs = new FileStream(_fullFilePath,
                                                           FileMode.Open, FileAccess.Read, FileShare.Read);

                            Image image = Image.FromStream(fs);
                            fileWidth  = image.Width;
                            fileHeight = image.Height;
                            fs.Close();
                            try
                            {
                                m.getProperty("umbracoWidth").Value  = fileWidth.ToString();
                                m.getProperty("umbracoHeight").Value = fileHeight.ToString();
                            }
                            catch
                            {
                            }
                        }
                    }
                    catch
                    {
                    }

                    return(fileUrl);
                }
                else
                {
                    throw new ArgumentException(
                              "Image Support is turned off in this channel. Modify channel settings in umbraco to enable image support.");
                }
            }
            return(new UrlData());
        }