Exemple #1
0
        internal static IEnumerable <IFileInfo> DeserializeFileInfo(string content)
        {
            if (string.IsNullOrEmpty(content))
            {
                yield break;
            }

            foreach (var file in content.FromJson <int[]>().ToArray())
            {
                IFileInfo fileInfo = null;
                try
                {
                    fileInfo = FileManager.Instance.GetFile(file);
                }
                catch
                {
                    // throw new ApplicationException(string.Format("Error loading file properties for FileID '{0}'", file), ex);

                    // On second thought, I don't know how much sense it makes to be throwing an exception here.  If the file
                    // has been deleted or is otherwise unavailable, there's really no reason we can't continue on handling the
                    // ContentItem without its attachment.  Better than the yellow screen of death? --cbond

                    DnnLog.Warn("Unable to load file properties for File ID {0}", file);
                }

                if (fileInfo != null)
                {
                    yield return(fileInfo);
                }
            }
        }
Exemple #2
0
        public void TryIt()
        {
            var currentDelay    = (int)Delay.TotalMilliseconds;
            int retrysRemaining = MaxRetries;

            do
            {
                try
                {
                    Action();
                    DnnLog.Trace("Action succeeded - {0}", Description);
                    return;
                }
                catch (Exception)
                {
                    if (retrysRemaining <= 0)
                    {
                        DnnLog.Warn("All retries of action failed - {0}", Description);
                        throw;
                    }

                    DnnLog.Trace("Retrying action {0} - {1}", retrysRemaining, Description);
                    SleepAction.Invoke(currentDelay);

                    const double epsilon = 0.0001;
                    if (Math.Abs(DelayMultiplier - 1) > epsilon)
                    {
                        currentDelay = (int)(currentDelay * DelayMultiplier);
                    }
                }
                retrysRemaining--;
            } while (true);
        }
        public string GetString(string key, string resourceFileRoot, string language, PortalSettings portalSettings, bool disableShowMissingKeys)
        {
            //make the default translation property ".Text"
            if (key.IndexOf(".", StringComparison.Ordinal) < 1)
            {
                key += ".Text";
            }
            string resourceValue = Null.NullString;
            bool   keyFound      = TryGetStringInternal(key, language, resourceFileRoot, portalSettings, ref resourceValue);

            //If the key can't be found then it doesn't exist in the Localization Resources
            if (Localization.ShowMissingKeys && !disableShowMissingKeys)
            {
                if (keyFound)
                {
                    resourceValue = "[L]" + resourceValue;
                }
                else
                {
                    resourceValue = "RESX:" + key;
                }
            }

            if (!keyFound)
            {
                DnnLog.Warn("Missing localization key. key:{0} resFileRoot:{1} threadCulture:{2} userlan:{3}", key, resourceFileRoot, Thread.CurrentThread.CurrentUICulture, language);
            }

            return(resourceValue);
        }
        public static DesktopModuleInfo GetDesktopModuleByFriendlyName(string friendlyName)
        {
            var module = (from kvp in GetDesktopModulesInternal(Null.NullInteger) where kvp.Value.FriendlyName == friendlyName select kvp.Value).FirstOrDefault();

            if (module == null)
            {
                DnnLog.Warn("Unable to find module by friendly name. Name:{0}", friendlyName);
            }

            return(module);
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetDesktopModuleByModuleName gets a Desktop Module by its Name
        /// </summary>
        /// <remarks>This method uses the cached Dictionary of DesktopModules.  It first checks
        /// if the DesktopModule is in the cache.  If it is not in the cache it then makes a call
        /// to the Dataprovider.</remarks>
        /// <param name="moduleName">The name of the Desktop Module to get</param>
        /// <param name="portalID">The ID of the portal</param>
        /// <history>
        ///     [cnurse]	01/13/2008   Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static DesktopModuleInfo GetDesktopModuleByModuleName(string moduleName, int portalID)
        {
            DesktopModuleInfo desktopModuleByModuleName = (from kvp in GetDesktopModulesInternal(portalID)
                                                           where kvp.Value.ModuleName == moduleName
                                                           select kvp.Value).FirstOrDefault();

            if (desktopModuleByModuleName == null)
            {
                DnnLog.Warn("Unable to find module by name. Name:{0} portalId:{1}", moduleName, portalID);
            }

            return(desktopModuleByModuleName);
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetDesktopModuleByPackageID gets a Desktop Module by its Package ID
        /// </summary>
        /// <param name="packageID">The ID of the Package</param>
        /// <history>
        ///     [cnurse]	01/15/2008   Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static DesktopModuleInfo GetDesktopModuleByPackageID(int packageID)
        {
            DesktopModuleInfo desktopModuleByPackageID = (from kvp in GetDesktopModulesInternal(Null.NullInteger)
                                                          where kvp.Value.PackageID == packageID
                                                          select kvp.Value)
                                                         .FirstOrDefault();

            if (desktopModuleByPackageID == null)
            {
                DnnLog.Warn("Unable to find module by package ID. ID:{0}", packageID);
            }

            return(desktopModuleByPackageID);
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetDesktopModule gets a Desktop Module by its ID
        /// </summary>
        /// <remarks>This method uses the cached Dictionary of DesktopModules.  It first checks
        /// if the DesktopModule is in the cache.  If it is not in the cache it then makes a call
        /// to the Dataprovider.</remarks>
        /// <param name="desktopModuleID">The ID of the Desktop Module to get</param>
        /// <param name="portalID">The ID of the portal</param>
        /// <history>
        ///     [cnurse]	01/13/2008   Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static DesktopModuleInfo GetDesktopModule(int desktopModuleID, int portalID)
        {
            var module = (from kvp in GetDesktopModulesInternal(portalID)
                          where kvp.Value.DesktopModuleID == desktopModuleID
                          select kvp.Value)
                         .FirstOrDefault();

            if (module == null)
            {
                module = (from kvp in GetDesktopModulesInternal(Null.NullInteger)
                          where kvp.Value.DesktopModuleID == desktopModuleID
                          select kvp.Value)
                         .FirstOrDefault();
            }

            if (module == null)
            {
                DnnLog.Warn("Unable to find module by module ID. ID:{0} PortalID:{1}", desktopModuleID, portalID);
            }

            return(module);
        }
Exemple #8
0
        public override Stream GetFileStream(IFolderInfo folder, string fileName)
        {
            Requires.NotNull("folder", folder);
            Requires.NotNullOrEmpty("fileName", fileName);

            Stream stream = null;

            try
            {
                stream = FileWrapper.Instance.OpenRead(GetActualPath(folder, fileName));
            }
            catch (IOException iex)
            {
                DnnLog.Warn(iex.Message);
            }
            catch (Exception ex)
            {
                DnnLog.Error(ex);
            }

            return(stream);
        }
Exemple #9
0
        private static void CheckIconOnDisk(string path)
        {
            using (_iconsStatusOnDisk.GetReadLock())
            {
                if (_iconsStatusOnDisk.ContainsKey(path))
                {
                    return;
                }
            }

            using (_iconsStatusOnDisk.GetWriteLock())
            {
                if (!_iconsStatusOnDisk.ContainsKey(path))
                {
                    _iconsStatusOnDisk.Add(path, true);
                    string iconPhysicalPath = Path.Combine(Globals.ApplicationMapPath, path.Replace('/', '\\'));
                    if (!File.Exists(iconPhysicalPath))
                    {
                        DnnLog.Warn(string.Format("Icon Not Present on Disk {0}", iconPhysicalPath));
                    }
                }
            }
        }
Exemple #10
0
        /// <summary>
        ///   ShowImage displays the Preview Image
        /// </summary>
        /// <history>
        ///   [cnurse]	08/01/2006  created
        /// </history>
        private void ShowImage()
        {
            var image = (FileInfo)FileManager.Instance.GetFile(FileID);

            if (image != null)
            {
                _imgPreview.ImageUrl = FileManager.Instance.GetUrl(image);
                try
                {
                    Utilities.CreateThumbnail(image, _imgPreview, MaxWidth, MaxHeight);
                }
                catch (Exception)
                {
                    DnnLog.Warn("Unable to create thumbnail for {0}", image.PhysicalPath);
                    _pnlRightDiv.Visible = false;
                }

                _pnlRightDiv.Visible = true;
            }
            else
            {
                _pnlRightDiv.Visible = false;
            }
        }
Exemple #11
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// The cmdAdd_Click runs when the Add Button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// </remarks>
        /// <history>
        ///   [cnurse] 16/9/2004  Updated for localization, Help and 508
        /// </history>
        /// -----------------------------------------------------------------------------
        private void cmdAdd_Click(object sender, EventArgs e)
        {
            try
            {
                CheckSecurity();
                var strMessage = "";

                var postedFile = cmdBrowse.PostedFile;

                //Get localized Strings
                var strInvalid = Localization.GetString("InvalidExt", LocalResourceFile);

                var strFileName  = Path.GetFileName(postedFile.FileName);
                var strExtension = Path.GetExtension(strFileName);
                if (!String.IsNullOrEmpty(postedFile.FileName))
                {
                    switch (FileType)
                    {
                    case UploadType.File:     //content files
                        try
                        {
                            var folder      = FolderManager.Instance.GetFolder(FolderPortalID, ddlFolders.SelectedValue);
                            var fileManager = Services.FileSystem.FileManager.Instance;
                            var file        = fileManager.AddFile(folder, strFileName, postedFile.InputStream, true, true, postedFile.ContentType);
                            if (chkUnzip.Checked && file.Extension == "zip")
                            {
                                fileManager.UnzipFile(file, folder);
                            }
                        }
                        catch (PermissionsNotMetException exc)
                        {
                            DnnLog.Warn(exc);
                            strMessage += "<br />" + string.Format(Localization.GetString("InsufficientFolderPermission"), ddlFolders.SelectedValue);
                        }
                        catch (NoSpaceAvailableException exc)
                        {
                            DnnLog.Warn(exc);
                            strMessage += "<br />" + string.Format(Localization.GetString("DiskSpaceExceeded"), strFileName);
                        }
                        catch (InvalidFileExtensionException exc)
                        {
                            DnnLog.Warn(exc);
                            strMessage += "<br />" + string.Format(Localization.GetString("RestrictedFileType"), strFileName, Host.AllowedExtensionWhitelist.ToDisplayString());
                        }
                        catch (Exception exc)
                        {
                            DnnLog.Error(exc);
                            strMessage += "<br />" + string.Format(Localization.GetString("SaveFileError"), strFileName);
                        }
                        break;
                    }
                }
                else
                {
                    strMessage = Localization.GetString("NoFile", LocalResourceFile);
                }
                if (phPaLogs.Controls.Count > 0)
                {
                    tblLogs.Visible = true;
                }
                else if (String.IsNullOrEmpty(strMessage))
                {
                    UI.Skins.Skin.AddModuleMessage(this, String.Format(Localization.GetString("FileUploadSuccess", LocalResourceFile), strFileName), ModuleMessage.ModuleMessageType.GreenSuccess);
                }
                else
                {
                    lblMessage.Text = strMessage;
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Exemple #12
0
 /// -----------------------------------------------------------------------------
 /// <summary>
 /// The AddWarning method adds a new LogEntry of type Warning to the Logs collection
 /// </summary>
 /// <param name="warning">The description of the LogEntry</param>
 /// <history>
 ///     [cnurse]	07/24/2007  created
 /// </history>
 /// -----------------------------------------------------------------------------
 public void AddWarning(string warning)
 {
     _logs.Add(new LogEntry(LogType.Warning, warning));
     DnnLog.Warn(warning);
     _hasWarnings = true;
 }