Esempio n. 1
0
		public static void Configure(IInitDataService dataService, StorageDomain domain)
		{
			if (dataService == null)
				throw new ArgumentNullException("dataService");

			if (domain == StorageDomain.UserCacheData)
			{
				dataService.Initialize(Path.Combine(
						RssBanditApplication.GetLocalUserPath(),
						"Cache"));
			}
			else

				if (domain == StorageDomain.UserData)
				{
					dataService.Initialize(
						RssBanditApplication.GetUserPersonalPath());
				}
				else

					if (domain == StorageDomain.UserRoamingData)
					{
						dataService.Initialize(
							RssBanditApplication.GetUserPath());
					}
					else

						Debug.Assert(false, "No data service for StorageDomain: " + domain);
		}
Esempio n. 2
0
		/// <summary>
		/// Gets the required per storage domain data service.
		/// </summary>
		/// <param name="domain">The domain.</param>
		/// <returns></returns>
		public static object GetService(StorageDomain domain)
		{
			IInitDataService service = new FileStorageDataService();
			if (domain == StorageDomain.UserCacheData)
			{
				service.Initialize(Path.Combine(
						RssBanditApplication.GetLocalUserPath(),
						"Cache"));
			}
			else

				if (domain == StorageDomain.UserData)
				{
					service.Initialize(
						RssBanditApplication.GetUserPersonalPath());
				}
				else

					if (domain == StorageDomain.UserRoamingData)
					{
						service.Initialize(
							RssBanditApplication.GetUserPath());
					}
					else

						Debug.Assert(false, "No data service for StorageDomain: " + domain);

			return service;
		}
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeletedItemsFeed"/> class.
        /// </summary>
        /// <param name="migratedItemsOwner">The migrated items owner.</param>
        public DeletedItemsFeed(FeedSourceEntry migratedItemsOwner) :
            base(migratedItemsOwner, RssBanditApplication.GetDeletedItemsFileName(),
                 SR.FeedNodeDeletedItemsCaption,
                 SR.FeedNodeDeletedItemsDesc, false)
        {
            // set this to indicate required migration:
            migrationRequired = RssBanditApplication.PersistedSettings.GetProperty(Ps.DeletedItemsFeedMigrationRequired, true);

            using (XmlReader reader = this.GetDefaultReader())
                LoadItems(reader, migratedItemsOwner);
        }
Esempio n. 4
0
        public NewsItemReferrerFilter(RssBanditApplication app)
        {
            UserIdentity identity;

            if (app.IdentityManager.Identities.TryGetValue(app.Preferences.UserIdentityForComments, out identity))
            {
                InitWith(identity);
            }

            // get notified, if prefs are changed (new default identity for comments)
            app.PreferencesChanged += OnPreferencesChanged;
        }
 public RemoteFeedlistThreadHandler(Operation operation, RssBanditApplication rssBanditApp,
                                    RemoteStorageProtocolType protocol, string remoteLocation,
                                    string credentialUser, string credentialPwd, IPersistedSettings settings)
 {
     operationToRun      = operation;
     this.rssBanditApp   = rssBanditApp;
     remoteProtocol      = protocol;
     this.remoteLocation = remoteLocation;
     this.credentialUser = credentialUser;
     credentialPassword  = credentialPwd;
     this.settings       = settings;
 }
Esempio n. 6
0
        /// <summary>
        /// When the user changes any preferences, this method is called to
        /// make sure that we have a correct identity referer url.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPreferencesChanged(object sender, EventArgs e)
        {
            RssBanditApplication app = sender as RssBanditApplication;

            if (app != null)
            {
                UserIdentity identity;
                if (app.IdentityManager.Identities.TryGetValue(app.Preferences.UserIdentityForComments, out identity))
                {
                    InitWith(identity);
                }
            }
        }
Esempio n. 7
0
        public CategoryProperties(string title, int refreshRate, TimeSpan maxItemAge, string stylesheet) : this()
        {
            this.textBox2.Text = title;

            this.comboBox1.Items.Clear();
            if (!Utils.RefreshRateStrings.Contains(refreshRate.ToString()))
            {
                Utils.RefreshRateStrings.Add(refreshRate.ToString());
            }
            this.comboBox1.DataSource = Utils.RefreshRateStrings;
            this.comboBox1.Text       = refreshRate.ToString();

            this.MaxItemAge = maxItemAge;
            //this.checkEnableAlerts.Checked = false;

            // item formatters
            string tmplFolder = RssBanditApplication.GetTemplatesPath();

            this.checkCustomFormatter.Enabled = false;
            this.comboFormatters.Items.Clear();

            if (Directory.Exists(tmplFolder))
            {
                string[] tmplFiles = Directory.GetFiles(tmplFolder, "*.fdxsl");

                if (tmplFiles.GetLength(0) > 0)
                {
                    this.checkCustomFormatter.Enabled = true;
                    foreach (string filename in tmplFiles)
                    {
                        this.comboFormatters.Items.Add(Path.GetFileNameWithoutExtension(filename));
                    }
                }

                if (stylesheet != null &&
                    stylesheet.Length > 0 &&
                    File.Exists(Path.Combine(tmplFolder, stylesheet + ".fdxsl")))
                {
                    this.comboFormatters.Text         = stylesheet;
                    this.checkCustomFormatter.Checked = true;
                }
            }
            else
            {
                this.comboFormatters.Text         = String.Empty;
                this.checkCustomFormatter.Checked = false;
            }
            this.checkCustomFormatter_CheckedChanged(null, null);
            this.comboFormatters.Refresh();
        }
Esempio n. 8
0
        /// <summary>
        /// Walk all the assemblies in the specified directory looking
        /// for classes that implements Syndication.Extensibility.IBlogExtension.
        /// </summary>
        /// <param name="path">path to search for service assemblies</param>
        /// <returns>ArrayList containing suitable processors found</returns>
        /// <permission cref="ReflectionPermission">Used to find extensions</permission>
        public static IList <IBlogExtension> SearchForIBlogExtensions(string path)
        {
            AppDomain loaderDomain = null;

            try
            {
                Type managerType = typeof(ServiceManager);

                string fullPath = RssBanditApplication.GetPlugInPath();
                loaderDomain = CreateLoaderDomain(RssBanditApplication.GetPlugInRelativePath());
                ServiceManager srvFinder = (ServiceManager)loaderDomain.CreateInstanceAndUnwrap(
                    Assembly.GetAssembly(managerType).FullName,
                    managerType.FullName);

                IEnumerable <Type> extensions = srvFinder.SearchForIBlogExtensionTypes(fullPath);

                List <IBlogExtension> extensionInstances = new List <IBlogExtension>();
                foreach (Type foundType in extensions)
                {
                    if (foundType.Equals(typeof(IBlogExtension)))
                    {
                        continue;
                    }
                    try
                    {
                        IBlogExtension extension = (IBlogExtension)Activator.CreateInstance(foundType);
                        extensionInstances.Add(extension);
                    }
                    catch (Exception ex)
                    {
                        _log.Error("Plugin of type '" + foundType.FullName + "' could not be activated.", ex);
                    }
                }

                return(extensionInstances);
            }
            finally
            {
                if (loaderDomain != null)
                {
                    AppDomain.Unload(loaderDomain);
                }
            }
        }
Esempio n. 9
0
//		static FontStyle[]	p_fontStyles = new FontStyle[6]{FontStyle.Regular,FontStyle.Italic, FontStyle.Bold, FontStyle.Regular, FontStyle.Regular, FontStyle.Italic};
//		static Color []		p_foreColors = new Color[6]{SystemColors.ControlText, SystemColors.ControlText, SystemColors.ControlText, Color.Blue, Color.Red, Color.Green};

        static FontColorHelper()
        {
            p_currentColorTable = Office2003ColorTable.Colors;
            //TODO use that display styles/font/color consistently over the UI:
//			if (Win32.IsOSAtLeastWindowsVista)
//				p_currentColorTable = Office2007ColorTable.Colors;

            p_foreColorStyles = new ColorStyleContainer[p_defaultForeColorStyles.Length];
            for (int i = 0; i < p_foreColorStyles.Length; i++)
            {
                p_foreColorStyles[i] = p_defaultForeColorStyles[i].Clone();
            }

            // can be overridden by App.config settings:
            p_foreColorStyles[(int)FontStates.UnreadCounter].FontStyle =
                RssBanditApplication.ReadAppSettingsEntry("UnreadCounterFontStyle", DefaultUnreadCounterStyle);
            p_foreColorStyles[(int)FontStates.UnreadCounter].Color =
                RssBanditApplication.ReadAppSettingsEntry("UnreadCounterFontColor", DefaultUnreadCounterColor);
        }
Esempio n. 10
0
        /// <summary>
        /// Loads the items.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="migratedItemsOwner">The migrated items owner.</param>
        protected void LoadItems(XmlReader reader, FeedSourceEntry migratedItemsOwner)
        {
            if (feedInfo.ItemsList.Count > 0)
            {
                feedInfo.ItemsList.Clear();
            }

            bool success = false;

            if (reader != null)
            {
                try{
                    XmlDocument doc = new XmlDocument();
                    doc.Load(reader);
                    foreach (XmlElement elem in doc.SelectNodes("//item"))
                    {
                        NewsItem item = RssParser.MakeRssItem(this, new XmlNodeReader(elem));

                        // We do this because the flagged items are stored in one "feed",
                        // but gets displayed one node per flag status. If one item is unread,
                        // all flag nodes gets the "unread" state.
                        item.BeenRead = true;

                        item.FeedDetails = this.feedInfo;
                        if (migrationRequired)
                        {
                            item = MigrateItem(item, migratedItemsOwner);
                        }

                        if (item != null)
                        {
                            feedInfo.ItemsList.Add(item);
                        }
                    }

                    success = true;
                }catch (Exception e) {
                    ExceptionManager.GetInstance().Add(RssBanditApplication.CreateLocalFeedRequestException(e, this, this.feedInfo), migratedItemsOwner);
                }
            }

            OnItemsLoaded(success);
        }
        /// <summary>
        /// Does the actual work of determining the top stories
        /// </summary>
        protected override void Run()
        {
            try {
                FeedSourceEntry entry = rssBanditApp.CurrentFeedSource;

                if (entry != null)
                {
                    int numDays = RssBanditApplication.ReadAppSettingsEntry("TopStoriesTimeSpanInDays", 7);
                    TopStories = new List <RelationHRefEntry>(entry.Source.GetTopStories(new TimeSpan(numDays, 0, 0, 0), 10));
                    this.GenerateTopStoriesPage(entry.Name);
                }
            } catch (ThreadAbortException) {
                // eat up
            } catch (Exception ex) {
                p_operationException = ex;
                _log.Error("GetTopStories() exception", ex);
            } finally {
                WorkDone.Set();
            }
        }
Esempio n. 12
0
        public UnreadItemsNode(LocalFeedsFeed itemStore, int imageIndex, int selectedImageIndex, ContextMenuStrip menu) :
            base(itemStore, imageIndex, selectedImageIndex, menu)
        {
            // TODO: we should extend the interface ICoreApplication
            app = (RssBanditApplication)IoC.Resolve <ICoreApplication>();

            app.FeedSourceAdded   += app_FeedSourceAdded;
            app.FeedSourceChanged += app_FeedSourceChanged;
            app.FeedSourceDeleted += app_FeedSourceDeleted;

            if (app.FeedSources.Count > 1)
            {
                foreach (FeedSourceEntry e in app.FeedSources.Sources)
                {
                    UnreadItemsNodePerSource child = new UnreadItemsNodePerSource(
                        e, itemStore, imageIndex, selectedImageIndex, menu);
                    this.Nodes.Add(child);
                    childrenBySourceID.Add(e.ID, child);
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FlaggedItemsFeed"/> class.
        /// </summary>
        /// <param name="migratedItemsOwner">The migrated items owner.</param>
        /// <param name="reader">The reader.</param>
        public FlaggedItemsFeed(FeedSourceEntry migratedItemsOwner, XmlReader reader) :
            base(migratedItemsOwner, RssBanditApplication.GetFlagItemsFileName(),
                 SR.FeedNodeFlaggedFeedsCaption,
                 SR.FeedNodeFlaggedFeedsDesc, false)
        {
            runSelfHealingFlagStatus = RssBanditApplication.PersistedSettings.GetProperty(
                Ps.FlaggedItemsFeedSelfHealingFlagStatusRequired, true);

            // set this to indicate required migration:
            migrationRequired = runSelfHealingFlagStatus || RssBanditApplication.PersistedSettings.GetProperty(
                Ps.FlaggedItemsFeedMigrationRequired, true);

            if (reader != null)
            {
                LoadItems(reader, migratedItemsOwner);
            }
            else
            {
                using (reader = this.GetDefaultReader())
                    LoadItems(reader, migratedItemsOwner);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Walk all the AddIns assembly locations
        /// for classes that implements RssBandit.UIServices.IAddInPackage.
        /// Then it builds the full AddInList by initializing the AddIn name to the
        /// base assembly file name and creates the type instances.
        /// </summary>
        /// <param name="assemblies">AddInList with AddIn assembly locations</param>
        /// <returns>AddInList containing suitable types implementing IAddInPackages found</returns>
        /// <permission cref="ReflectionPermission">Used to find IAddInPackages implementors</permission>
        public static IList <IAddIn> PopulateAndInitAddInPackages(IList <IAddIn> assemblies)
        {
            List <IAddIn> newList = new List <IAddIn>();

            if (assemblies == null || assemblies.Count == 0)
            {
                return(newList);
            }

            AppDomain loaderDomain = null;

            try
            {
                loaderDomain = CreateLoaderDomain(RssBanditApplication.GetAddInInRelativePath());

                ServiceManager srvFinder =
                    (ServiceManager)
                    loaderDomain.CreateInstanceAndUnwrap(
                        Assembly.GetAssembly(typeof(ServiceManager)).FullName,
                        "AppInteropServices.ServiceManager");
                IDictionary <string, IEnumerable <Type> > addInTypes =
                    srvFinder.SearchForIAddInPackagesTypes(assemblies);

                foreach (IAddIn a in assemblies)
                {
                    if (a.Location == null || !addInTypes.ContainsKey(a.Location))
                    {
                        continue;
                    }

                    List <IAddInPackage> instances  = new List <IAddInPackage>();
                    IEnumerable <Type>   foundTypes = addInTypes[a.Location];
                    foreach (Type foundType in foundTypes)
                    {
                        try
                        {
                            IAddInPackage addInPackage = (IAddInPackage)Activator.CreateInstance(foundType);
                            if (addInPackage != null)
                            {
                                instances.Add(addInPackage);
                            }
                        }
                        catch (Exception ex)
                        {
                            _log.Error("AddIn of type '" + foundType.FullName + "' could not be activated.", ex);
                        }
                    }

                    if (instances.Count > 0)
                    {
                        newList.Add(new AddIn(a.Location, Path.GetFileNameWithoutExtension(a.Location), instances));
                    }
                }
                return(newList);
            }
            finally
            {
                if (loaderDomain != null)
                {
                    AppDomain.Unload(loaderDomain);
                }
            }
        }
 /// <summary>
 /// Initializes the object with the calling RssBanditApplication instance.
 /// </summary>
 /// <param name="rssBanditApp">The calling RssBanditApplication</param>
 /// <param name="memeFile">The file to write the Top Stories to after they have been determined.</param>
 public TopStoriesThreadHandler(RssBanditApplication rssBanditApp, string memeFile)
 {
     this.rssBanditApp = rssBanditApp;
     this.memeFile     = memeFile;
 }
Esempio n. 16
0
 static PostReplyForm()
 {
     useEnglishReplyPrefix = RssBanditApplication.ReadAppSettingsEntry("UseEnglishReplyPrefix", false);
 }
        /// <summary>
        /// Synchronizes the current state of RSS Bandit from the data in the stream.
        /// </summary>
        /// <param name="stream">The data to synchronize RSS Bandit from</param>
        /// <param name="syncFormat">The synchronization format used</param>
        public void Synchronize(Stream stream, SynchronizationFormat syncFormat)
        {
            /* we support both old version's subscriptions.xml and feedlist.xml */

            string feedsources          = Path.GetFileName(RssBanditApplication.GetFeedSourcesFileName());
            string subscriptionsOld     = Path.GetFileName(RssBanditApplication.OldVersionSupport.GetSubscriptionsFileName());
            string feedlistOld          = Path.GetFileName(RssBanditApplication.OldVersionSupport.GetFeedListFileName());
            string flaggeditems         = Path.GetFileName(RssBanditApplication.GetFlagItemsFileName());
            string searchfolders        = Path.GetFileName(RssBanditApplication.GetSearchFolderFileName());
            string sentitems            = Path.GetFileName(RssBanditApplication.GetSentItemsFileName());
            string watcheditems         = Path.GetFileName(RssBanditApplication.GetWatchedItemsFileName());
            bool   subscriptionsXmlSeen = false;


            if (syncFormat == SynchronizationFormat.Zip)
            {
                ZipInputStream zis = new ZipInputStream(stream);

                ZipEntry theEntry;
                while ((theEntry = zis.GetNextEntry()) != null)
                {
                    if (theEntry.Name == feedsources)
                    {
                        rssBanditApp.FeedSources.LoadFeedSources(zis);
                    }
                    else if (!subscriptionsXmlSeen && (theEntry.Name == subscriptionsOld))
                    {
                        subscriptionsXmlSeen = true;
                        rssBanditApp.BanditFeedSource.ReplaceFeedlist(zis);
                    }
                    else if (!subscriptionsXmlSeen && (theEntry.Name == feedlistOld))
                    {
                        rssBanditApp.BanditFeedSource.ReplaceFeedlist(zis);
                    }
                    else if (theEntry.Name == flaggeditems)
                    {
                        LocalFeedsFeed flaggedItemsFeed = rssBanditApp.FlaggedItemsFeed;
                        LocalFeedsFeed lff = new FlaggedItemsFeed(rssBanditApp.BanditFeedSourceEntry, new XmlTextReader(zis));
                        rssBanditApp.ClearFlaggedItems();

                        foreach (NewsItem item in lff.Items)
                        {
                            flaggedItemsFeed.Add(item);
                            rssBanditApp.ReFlagNewsItem(item);
                        }
                    }
                    else if (theEntry.Name == sentitems)
                    {
                        LocalFeedsFeed sentItemsFeed = rssBanditApp.SentItemsFeed;
                        LocalFeedsFeed lff2          = new SentItemsFeed(rssBanditApp.BanditFeedSourceEntry, new XmlTextReader(zis));

                        sentItemsFeed.Add(lff2);
                    }
                    else if (theEntry.Name == watcheditems)
                    {
                        LocalFeedsFeed watchedItemsFeed = rssBanditApp.WatchedItemsFeed;
                        LocalFeedsFeed lff2             = new WatchedItemsFeed(rssBanditApp.BanditFeedSourceEntry, new XmlTextReader(zis));

                        watchedItemsFeed.Add(lff2);
                    }
                    else if (theEntry.Name == searchfolders)
                    {
                        XmlSerializer ser = XmlHelper.SerializerCache.GetSerializer(typeof(FinderSearchNodes));
                        rssBanditApp.FindersSearchRoot = (FinderSearchNodes)ser.Deserialize(zis);
                    }
                    else
                    {
                        // set files managed by Bandit data storage:
                        IUserRoamingDataService dataService = IoC.Resolve <IUserRoamingDataService>();
                        if (dataService != null)
                        {
                            if (DataEntityName.None != dataService.SetContentForDataFile(theEntry.Name, zis))
                            {
                                continue;                                 // was handled here
                            }
                        }

                        // remaining: set files managed by NewComponents feed source data storage:
                        bool handled = false;
                        rssBanditApp.FeedSources.ForEach(
                            f =>
                        {
                            if (!handled && f.SetContentForDataServiceFile(theEntry.Name, zis))
                            {
                                handled = true;
                            }
                        });

                        if (handled)
                        {
                            continue;
                        }

                        rssBanditApp.FeedSources.ForEach(
                            f =>
                        {
                            if (!handled && f.SubscriptionLocation.Location.EndsWith(theEntry.Name, StringComparison.OrdinalIgnoreCase))
                            {
                                if (f.Type == FeedSourceType.DirectAccess)
                                {
                                    subscriptionsXmlSeen = true;                                                // do not import/replace from older subscription version files
                                }
                                f.ReplaceFeedlist(zis);
                                handled = true;
                            }
                        });
                    }
                } //while

                zis.Close();
            } //if(syncFormat == SynchronizationFormat.Zip
        }
        /// <summary>
        /// Upload application state either as a ZIP file or as a SIAM file
        /// </summary>
        /// <param name="syncFormat">The synchronization format to use</param>
        public void RunUpload(SynchronizationFormat syncFormat)
        {
            List <string> files = new List <string>(new[] {
                RssBanditApplication.GetFeedSourcesFileName(),
                RssBanditApplication.GetFlagItemsFileName(),
                RssBanditApplication.GetSearchFolderFileName(),
                RssBanditApplication.GetSentItemsFileName(),
                RssBanditApplication.GetWatchedItemsFileName()
            });

            // add files managed by Bandit data storage (column layout and user identities):
            IUserRoamingDataService dataService = IoC.Resolve <IUserRoamingDataService>();

            if (dataService != null)
            {
                files.AddRange(dataService.GetUserDataFileNames());
            }

            // add files managed by NewComponents feed source data storage (e.g. Nntp Server Definitions filename) :
            rssBanditApp.FeedSources.ForEach(f =>
            {
                files.AddRange(f.GetDataServiceFiles());
                files.Add(f.SubscriptionLocation.Location);
            });

            try
            {
                rssBanditApp.SaveApplicationState();

                // Older versions support:
                FeedSourceEntry entry = rssBanditApp.FeedSources.Sources.FirstOrDefault(
                    fs => fs.SourceType == FeedSourceType.DirectAccess);

                if (entry != null)
                {
                    //copy BanditFeedSource feed list to subscriptions.xml (backward versions compatibility support)
                    File.Copy(entry.Source.SubscriptionLocation.Location,
                              RssBanditApplication.OldVersionSupport.GetSubscriptionsFileName(),
                              true);

                    //convert subscriptions.xml to feedlist.xml then save to temp folder
                    using (Stream xsltStream = Resource.GetStream("Resources.feedlist2subscriptions.xslt"))
                    {
                        XslCompiledTransform xslt = new XslCompiledTransform();
                        xslt.Load(new XmlTextReader(xsltStream));
                        xslt.Transform(
                            entry.Source.SubscriptionLocation.Location,
                            RssBanditApplication.OldVersionSupport.GetFeedListFileName());
                    }

                    files.AddRange(new[] {
                        RssBanditApplication.OldVersionSupport.GetSubscriptionsFileName(),
                        RssBanditApplication.OldVersionSupport.GetFeedListFileName()
                    });
                }

                using (MemoryStream tempStream = new MemoryStream())
                {
                    //ZipOutputStream zos;
                    switch (remoteProtocol)
                    {
                    case RemoteStorageProtocolType.UNC:

                        using (FileStream fs = FileHelper.OpenForWrite(
                                   Path.Combine(Environment.ExpandEnvironmentVariables(remoteLocation), remoteFileName)))
                        {
                            var zos = new ZipOutputStream(fs);
                            FileHelper.ZipFiles(files, zos);
                        }

                        break;

                    //case RemoteStorageProtocolType.dasBlog:

                    //    //save direct access feed list as OPML:
                    //    rssBanditApp.BanditFeedSource.SaveFeedList(tempStream, FeedListFormat.OPML);
                    //    tempStream.Position = 0;

                    //    XmlDocument doc = new XmlDocument();
                    //    doc.Load(tempStream);

                    //    // Send it to the web service
                    //    ConfigEditingService remoteStore = new ConfigEditingService();

                    //    remoteStore.Url = remoteLocation;
                    //    remoteStore.authenticationHeaderValue = new authenticationHeader();
                    //    remoteStore.authenticationHeaderValue.userName = credentialUser;
                    //    remoteStore.authenticationHeaderValue.password = credentialPassword;
                    //    remoteStore.Proxy = rssBanditApp.Proxy;

                    //    //TODO: figure out, when we have to use Credentials????
                    //    //	remoteStore.Credentials =   FeedSource.CreateCredentialsFrom(credentialUser, credentialPassword);

                    //    remoteStore.PostBlogroll("blogroll", doc.DocumentElement);
                    //        // ".opml" is appended by the service!
                    //    break;


                    case RemoteStorageProtocolType.FTP:                             // Send to FTP server

                        var zosFtp = new ZipOutputStream(tempStream);

                        FileHelper.ZipFiles(files, zosFtp);

                        tempStream.Position = 0;

                        var        ftpUri  = new Uri(remoteLocation);
                        UriBuilder builder = new UriBuilder(ftpUri);
                        builder.Path += builder.Path.EndsWith("/") ? remoteFileName : "/" + remoteFileName;


                        /* set up the FTP connection */
                        FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(builder.Uri);
                        ftpRequest.Method        = WebRequestMethods.Ftp.UploadFile;
                        ftpRequest.KeepAlive     = false;
                        ftpRequest.UseBinary     = true;
                        ftpRequest.UsePassive    = settings.GetProperty(Ps.FtpConnectionModePassive, true);
                        ftpRequest.Credentials   = new NetworkCredential(credentialUser, credentialPassword);
                        ftpRequest.ContentLength = tempStream.Length;

                        /* perform upload */
                        try
                        {
                            // The buffer size is set to 2kb
                            const int buffLength = 2048;
                            byte[]    buff       = new byte[buffLength];

                            // Stream to which the file to be upload is written
                            using (Stream strm = ftpRequest.GetRequestStream())
                            {
                                // Read from the file stream 2kb at a time
                                int contentLen = tempStream.Read(buff, 0, buffLength);

                                // Till Stream content ends
                                while (contentLen != 0)
                                {
                                    // Write Content from the file stream to the
                                    // FTP Upload Stream
                                    strm.Write(buff, 0, contentLen);
                                    contentLen = tempStream.Read(buff, 0, buffLength);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            //ToDO: Add support for switching between active and passive mode
                            p_operationException = ex;
                            _log.Error("FTP Upload Error", ex);
                        }

                        break;

                    case RemoteStorageProtocolType.WebDAV:

                        var zosDav = new ZipOutputStream(tempStream);

                        FileHelper.ZipFiles(files, zosDav);

                        var remoteUri = new Uri(remoteLocation.EndsWith("/")
                                                                ? remoteLocation + remoteFileName
                                                                : remoteLocation + "/" + remoteFileName);

                        tempStream.Position = 0;

                        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(remoteUri);
                        request.Method            = "PUT";
                        request.ContentType       = "application/zip";
                        request.AllowAutoRedirect = true;
                        request.UserAgent         = RssBanditApplication.UserAgent;
                        request.Proxy             = rssBanditApp.Proxy;

                        if (!string.IsNullOrEmpty(credentialUser))
                        {
                            NetworkCredential nc =
                                FeedSource.CreateCredentialsFrom(credentialUser, credentialPassword);

                            CredentialCache cc = new CredentialCache();
                            cc.Add(remoteUri, "Basic", nc);
                            cc.Add(remoteUri, "Digest", nc);
                            cc.Add(remoteUri, "NTLM", nc);

                            request.Credentials = cc;
                        }

                        byte[] bytes = new byte[tempStream.Length];
                        tempStream.Read(bytes, 0, bytes.Length);

                        request.ContentLength = bytes.Length;

                        Stream requestStream = request.GetRequestStream();
                        requestStream.Write(bytes, 0, bytes.Length);
                        requestStream.Close();

                        break;

                    default:

                        Debug.Assert(false,
                                     "unknown remote protocol: '" + remoteProtocol +
                                     "' in RemoteFeedlistThreadHandler");
                        break;
                    }
                }

                // Cool, we made it
            }
            catch (ThreadAbortException)
            {
                // eat up
            }
            catch (Exception ex)
            {
                p_operationException = ex;
                _log.Error("RunUpload(" + syncFormat + ") Exception", ex);
            }
            finally
            {
                WorkDone.Set();
            }
        }
Esempio n. 19
0
 internal DownloadManagerWindow(RssBanditApplication app) : this()
 {
     owner = app;
 }
 internal AutoDiscoveredFeedsMenuHandler(RssBanditApplication app) : this()
 {
     this.app = app;
 }
Esempio n. 21
0
        public FeedProperties(string title, string link, int refreshRate, TimeSpan maxItemAge, string currentCategory, string defaultCategory, ICollection <string> categories, string stylesheet) :
            this()
        {
            this.textBox1.Text = title;
            this.textBox2.Text = link;

            this.comboBox1.Items.Clear();
            if (!Utils.RefreshRateStrings.Contains(refreshRate.ToString()))
            {
                Utils.RefreshRateStrings.Add(refreshRate.ToString());
            }
            this.comboBox1.DataSource = Utils.RefreshRateStrings;
            this.comboBox1.Text       = refreshRate.ToString();

            tabAuthentication.Enabled = !RssHelper.IsNntpUrl(link);
            ClientCertificate         = null;

            //initialize category combo box
            foreach (string category in categories)
            {
                if (!string.IsNullOrEmpty(category))
                {
                    this.comboBox2.Items.Add(category);
                }
            }
            this.comboBox2.Items.Add(defaultCategory);
            if (currentCategory != null)
            {
                this.comboBox2.Text = currentCategory;
            }

            this.MaxItemAge = maxItemAge;
            this.checkEnableAlerts.Checked = false;

            // item formatters
            string tmplFolder = RssBanditApplication.GetTemplatesPath();

            this.checkCustomFormatter.Enabled = false;
            this.comboFormatters.Items.Clear();

            if (Directory.Exists(tmplFolder))
            {
                string[] tmplFiles = Directory.GetFiles(tmplFolder, "*.fdxsl");

                if (tmplFiles.GetLength(0) > 0)
                {
                    this.checkCustomFormatter.Enabled = true;
                    foreach (string filename in tmplFiles)
                    {
                        this.comboFormatters.Items.Add(Path.GetFileNameWithoutExtension(filename));
                    }
                }

                if (!string.IsNullOrEmpty(stylesheet) &&
                    File.Exists(Path.Combine(tmplFolder, stylesheet + ".fdxsl")))
                {
                    this.comboFormatters.Text         = stylesheet;
                    this.checkCustomFormatter.Checked = true;
                }
            }
            else
            {
                this.comboFormatters.Text         = String.Empty;
                this.checkCustomFormatter.Checked = false;
            }

            this.checkCustomFormatter_CheckedChanged(null, null);
            this.comboFormatters.Refresh();
        }