working on it ...

Filters

Explore Public Snippets

Sort by

Found 1,069 snippets matching: composite

    public by cghersi modified Jul 2, 2014  7471  1  7  2

    Java SWT: Combobox with AutoSuggestion feature

    This component can be safely used when you want to have a combobox with the capability to display automatic filtered suggestions based on the text already entered. It uses a couple of callback actions so that the caller can specify what to do when ENTER key is hit and how to load suggestions. The call back actions are specified by a simple interf
    package com.snip2code.ui.swt;
    
    import java.util.List;
    import java.util.Random;
    
    import org.apache.log4j.Logger;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.custom.StackLayout;
    import org.eclipse.swt.events.FocusAdapter;
    import org.eclipse.swt.events.FocusEvent;
    import org.eclipse.swt.events.KeyAdapter;
    import org.eclipse.swt.events.KeyEvent;
    import org.eclipse.swt.events.MouseAdapter;
    import org.eclipse.swt.events.MouseEvent;
    import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.graphics.Rectangle;
    import org.eclipse.swt.layout.FillLayout;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Control;
    import org.eclipse.swt.widgets.Event;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.Listener;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Table;
    import org.eclipse.swt.widgets.TableItem;
    import org.eclipse.swt.widgets.Text;
    
    import com.snip2code.utils.Utils;
    
    
    /**
     * (c) 2011 snip2code inc.
     * This software is property of snip2code inc. Use or reproduction without permission is prohibited 
     *
     * This widget creates a textfield with an autosuggestion feature.
     * The list of suggestion is shown when the user clicks on the text field or starts typing in the text field
     */
    public class AutoSuggestionComposite extends Composite {
    
    	protected static Logger log = Logger.getLogger(AutoSuggestionComposite.class);
    	
    	private Composite textBoxStackPanel;
    	private StackLayout textboxLayout;
    	private Text textBox;
    	private Label tooltip;
    	private Shell popupShell;
    	private Table table;
    	private String tooltipMsg;
    
    	private ICallback<String, List<String>> loadSuggestionAction;
    	private ICallback<String, String> onEnterAction;
    	
    	private String text;
    	private int numOfDisplayedSuggestions;
    	
    	private static final String POPUPVISIB = "$$$POPUP_VISIB";
    	
    	private String uniqueID; //used to differentiate AutoSuggestion composites in the same dialog
    	private static Random rdn = new Random();
    	
    	/**
    	 * Create the dialog.
    	 * @param parent
    	 * @param style
    	 * @param tooltipMsg message to display when no input is entered
    	 * @param numOfDisplayedSuggestions masimum number of items suggested in the popup of suggestions
    	 * @param loadSuggestionAction callback to routine that loads the suggestions for autocomplete
    	 * @param onEnterAction callback when enter is pressed on the textbox
    	 */
    	public AutoSuggestionComposite(Composite parent, int style, String tooltipMsg, int numOfDisplayedSuggestions, 
    			ICallback<String, List<String>> loadSuggestionAction, ICallback<String, String> onEnterAction) {
    		super(parent, style);
    
    		textboxLayout = new StackLayout();
    		this.loadSuggestionAction = loadSuggestionAction;
    		this.onEnterAction = onEnterAction;
    		this.numOfDisplayedSuggestions = numOfDisplayedSuggestions;
    		this.tooltipMsg = tooltipMsg;
    		
    		uniqueID = rdn.nextInt() + tooltipMsg;
    		
    		createDialogArea();
    	}
    	
    	private void createDialogArea() {
    		this.setBackground(SWTUIUtilities.WHITE);
    		GridLayout gridLayout = new GridLayout();
    		gridLayout.marginHeight = 0;
    		gridLayout.marginWidth = 0;
    		this.setLayout(gridLayout);
    
    		//Panel with textbox and tooltip:
    		textBoxStackPanel = new Composite(this, SWT.NONE);
    		textBoxStackPanel.setLayout(textboxLayout);
    		GridData gdPanel = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    		gdPanel.verticalIndent = 2;
    		textBoxStackPanel.setLayoutData(gdPanel);
    		
    		tooltip = new Label(textBoxStackPanel, SWT.NONE);
    		tooltip.setBackground(SWTUIUtilities.WHITE);
    		tooltip.setForeground(SWTUIUtilities.LIGHT_GREY);
    		tooltip.setFont(SWTUIUtilities.LBL_TEXT);
    		tooltip.setText(" " + tooltipMsg); //manual horizontal indent, cause StackLayout doesn't allow this feature
    		tooltip.addMouseListener(new MouseAdapter() {
    			@Override
    			public void mouseDown(MouseEvent e) {
    				setControlVisib(textBox, true);
    				textBoxStackPanel.layout();
    				textBox.setFocus();
    				loadSuggestions(null);
    			}
    		});
    		
    		textBox = new Text(textBoxStackPanel, SWT.NONE);
    		textBox.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    		textBox.setFont(SWTUIUtilities.LBL_TEXT);
    		textBox.setBackground(SWTUIUtilities.WHITE);
    		textBox.setData(POPUPVISIB, uniqueID);
    		
    		//popup for suggestions:
    		popupShell = new Shell(getShell().getDisplay(), SWT.ON_TOP);
    		popupShell.setLayout(new FillLayout());
    		popupShell.setData(POPUPVISIB, uniqueID);
    		popupShell.setBackground(SWTUIUtilities.WHITE);
    		table = new Table(popupShell, SWT.SINGLE);
        	table.getVerticalBar().setVisible(false);
    		table.setFont(SWTUIUtilities.LBL_TEXT);
    		table.setData(POPUPVISIB, uniqueID);
    		for (int i = 0; i < numOfDisplayedSuggestions; i++) {
    			new TableItem(table, SWT.NONE);
    		}
    		
    		//Key Listener for Keyboards events:
    		textBox.addKeyListener(new KeyAdapter() {
    			@Override
    			public void keyReleased(KeyEvent e) {
    				boolean loadSuggestions = true;
    				saveInput();
    				switch (e.keyCode) {
    					case SWT.ARROW_DOWN:
    						int index = (table.getSelectionIndex() + 1) % table.getItemCount();
    						table.setSelection(index);
    						e.doit = false;
    						break;
    					case SWT.ARROW_UP:
    						index = table.getSelectionIndex() - 1;
    						if (index < 0) 
    							index = table.getItemCount() - 1;
    						table.setSelection(index);
    						e.doit = false;
    						break;
    					case SWT.CR:
    					case SWT.LF:
    					case 16777296: //enter in numeric keypad
    						if (popupShell.isVisible() && table.getSelectionIndex() != -1) {
    							textBox.setText(table.getSelection()[0].getText());
    						}
    						
    						loadSuggestions = false;
    						execEnterAction();
    
    						break;
    					case SWT.ESC:
    						popupShell.setVisible(false);
    						break;
    				}
    
    				//only for printable characters, load search history:
    				if (loadSuggestions && (e.keyCode < 256))
    					loadSuggestions(textBox.getText());
    				
    				log.debug("End of key listener");
    			}
    		});
    		
    		//make sure the input entered in the text box is saved and ready to use:
    		textBox.addFocusListener(new FocusAdapter() {
    			@Override
    			public void focusLost(FocusEvent e) {
    				log.debug("Focus lost by textbox of autosugg from " + tooltipMsg);
    				saveInput();
    				checkTooltipVisib();
    				handleFocusLost();
    			}
    			
    			@Override
    			public void focusGained(FocusEvent e) {
    				if (isDisposed() || getShell().isDisposed() || getShell().getDisplay().isDisposed()) 
    					return;
    				log.debug("Focus gained by textbox of autosugg from " + tooltipMsg);
    				loadSuggestions(textBox.getText());
    			}
    		});
    		textBox.addSelectionListener(new SelectionAdapter() {
    			@Override
    			public void widgetSelected(SelectionEvent e) {
    				checkTooltipVisib();
    			}
    		});
    		
    		table.addListener(SWT.DefaultSelection, new Listener() {
    			public void handleEvent(Event event) {
    				textBox.setText(table.getSelection()[0].getText());
    				execEnterAction();
    			}
    		});
    		
    		//hide the popup of suggestions if the focus is out:
    		Listener focusOutListener = new Listener() {
    			public void handleEvent(Event event) {
    				handleFocusLost();
    			}
    		};
    		table.addListener(SWT.FocusOut, focusOutListener);
    		textBox.addListener(SWT.FocusOut, focusOutListener);
    		textBoxStackPanel.addListener(SWT.FocusOut, focusOutListener);
    		popupShell.addListener(SWT.FocusOut, focusOutListener);
    		this.addListener(SWT.FocusOut, focusOutListener);
    
    		getShell().addListener(SWT.Move, new Listener() {
    			public void handleEvent(Event event) {
    				popupShell.setVisible(false);
    				checkTooltipVisib();
    			}
    		});
    		
    		checkTooltipVisib();
    	}
    	
    	private void handleFocusLost() {
    		/* async is needed to wait until focus reaches its new Control */
    		if (isDisposed() || getShell().isDisposed() || getShell().getDisplay().isDisposed()) 
    			return;
    		getShell().getDisplay().asyncExec(new Runnable() {
    			public void run() {
    				log.debug("Running handleFocusLost for " + tooltipMsg);
    				if (isDisposed() || getShell().isDisposed() || getShell().getDisplay().isDisposed()) 
    					return;
    				Control control = getShell().getDisplay().getFocusControl();
    				log.debug("handleFocusLost for " + tooltipMsg + ": control is " + control + ";uniqueID:" + uniqueID);
    				if ((control == null) || (control.getData(POPUPVISIB) == null) || 
    					!control.getData(POPUPVISIB).toString().equals(uniqueID)) {
    					popupShell.setVisible(false);
    				}					
    			}
    		});
    	}
    	
    	/**
    	 * Determines the visibility of textbox content vs tooltip when the textbox is empty
    	 */
    	public void checkTooltipVisib() {
    		if (Utils.isNullOrEmpty(textBox.getText())) 
    			setControlVisib(tooltip, true);
    		else
    			setControlVisib(textBox, true);
    		textBoxStackPanel.layout();
    	}
    	
    	private void execEnterAction() {
    		saveInput();
    		popupShell.setVisible(false);
    		onEnterAction.exec(text);
    	}
    	
        private void loadSuggestions(String prefix) {
        	log.debug("loading suggestions for " + prefix);
    
    //		if (Utils.isNullOrEmpty(prefix))
    //			return;
        	
        	Rectangle textBounds = getShell().getDisplay().map(textBoxStackPanel, null, textBox.getBounds());
        	
    		//load suggestions:
        	List<String> suggestions = loadSuggestionAction.exec(prefix);
        	log.debug("loaded " + suggestions.size() + " suggestions");
        	
        	table.setItemCount(suggestions.size());
    		TableItem[] items = table.getItems();
    		int maxWidthOfItem = 0;
    		log.debug("Changing " + items.length + " items in TablePopup");
    		for (int i = 0; i < items.length; i++) {
    			if (i < suggestions.size()) {
    				String sugg = suggestions.get(i);
    				if (!Utils.isNullOrEmpty(sugg)) {
    					items[i].setText(sugg);
    					int w = items[i].getBounds().width;
    					if (w > maxWidthOfItem)
    						maxWidthOfItem = w;
    				}
    			}
    		}
    //		//avoid the display of horizontal scrollbar when not needed (10 is the width of the scrollbar)
    //		if ((maxWidthOfItem + 10) < textBounds.width)
    //			table.pack();
    		
    		//23 pixels is the height of 1 item in the drop down list; 
    		//always add a blank line at the end of the list to improve readability
    		int popupHeight = (suggestions.size() + 1) * 23; 
    		log.debug("popupHeight for [" + this.tooltipMsg + "]:" + popupHeight);
    		if (popupHeight <= 46)
    			popupHeight = 46; 
    	
    		//set a cap to the maximum height of the popup (17 lines):
    		if (popupHeight > 391) {
    			popupHeight = 391;
    			table.getVerticalBar().setVisible(true);
    		} else {
    			//avoid the display of horizontal scrollbar when not needed (10 is the width of the scrollbar)
    			if ((maxWidthOfItem + 10) < textBounds.width)
    				table.pack();
    			table.getVerticalBar().setVisible(false);
    		}
    		
    		log.debug("setBounds popup:" + textBounds.x + ";" + (textBounds.y + textBounds.height + 4) + ";" + 
    					textBounds.width + ";" + popupHeight);
    		popupShell.setBounds(textBounds.x, textBounds.y + textBounds.height + 4, textBounds.width, popupHeight);
    		popupShell.setVisible(true);		
        }
        
    	private void setControlVisib(Control c, boolean visible) {
    		if (c == null)
    			return;
    		
    		if (visible) 
    			textboxLayout.topControl = c;
    	}
    	
    	private void saveInput() {
    		text = textBox.getText();
    		if (text == null)
    			text = "";
    		text = text.trim();
    	}
    	
    	/**
    	 * Returns the content of the textbox
    	 */
    	public String getText() {
    		return text;
    	}
    	
    	/**
    	 * Sets the content of the textbox
    	 */
    	public void setText(String text) {
    		this.text = text;
    		textBox.setText(text);
    		setControlVisib(textBox, true);
    	}
    	
    	/**
    	 * Hides the popup of suggestions
    	 */
    	public void hideSuggestions() {
    		popupShell.setVisible(false);
    	}
    	
    	@Override
    	public void dispose() {
    		if (popupShell != null) {
    			hideSuggestions();
    			popupShell.dispose();
    		}
    
    		super.dispose();
    	}
    }

    public by Geometry modified Aug 6, 2016  789  0  6  0

    Format: Replaces the format item in a specified string with the string representation of a corresponding object in a specified array.

    Replaces the format item in a specified string with the string representation of a corresponding object in a specified array. A composite format string. An object array that contains zero or more objects to format. A copy of str in which the format items have been replaced by the string representation of the corresponding objec
    /// <summary>
    ///   Replaces the format item in a specified string with the string
    ///   representation of a corresponding object in a specified array.
    /// </summary>
    /// 
    /// <param name="str">A composite format string.</param>
    /// <param name="args">An object array that contains zero or more objects to format.</param>
    /// 
    /// <returns>
    ///   A copy of str in which the format items have been replaced by
    ///   the string representation of the corresponding objects in args.
    /// </returns>
    /// 
    public static string Format(this string str, params object[] args)
    {
        return String.Format(str, args);
    }

    public by msdn modified Jan 12, 2015  1260  0  6  0

    IsCompositeAdaptiveStreaming: Determines whether the file is valid composite smooth streaming uri.

    Determines whether the file is valid composite smooth streaming uri. The file to be validated. True if [is composite smooth streaming] [the specified file]; otherwise, false.
    /// <summary>
    /// The extension for the composite smooth streaming file.
    /// </summary>
    private const string CompositeSmoothStreamingExtension = ".CSM";
    
    /// <summary>
    /// Determines whether the file is valid composite smooth streaming uri.
    /// </summary>
    /// <param name="file">The file to be validated.</param>
    /// <returns>
    /// <c>True</c> if [is composite smooth streaming] [the specified file]; otherwise, <c>false</c>.
    /// </returns>
    public static bool IsCompositeAdaptiveStreaming(string file)
    {
        return !string.IsNullOrEmpty(file) && file.ToUpper(CultureInfo.InvariantCulture).Contains(CompositeSmoothStreamingExtension);
    }

    public by msdn modified Jan 10, 2015  1244  0  7  0

    MakeAggregationForPart: Parts get aggregation = composite to distinguish parts from properties

    Parts get aggregation = composite to distinguish parts from properties
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using System.Xml.Linq;
    using Microsoft.VisualStudio.ArchitectureTools.Extensibility.Uml;
    using Microsoft.VisualStudio.Modeling;
    using Microsoft.VisualStudio.Uml.AuxiliaryConstructs;
    using Microsoft.VisualStudio.Uml.Classes;
    using Microsoft.VisualStudio.Uml.Profiles;
    using meta = Microsoft.Example.MinimalCmof;
    
    /// <summary>
    /// Parts get aggregation = composite to distinguish parts from properties
    /// </summary>
    /// <param name="parent"></param>
    /// <param name="element"></param>
    private static void MakeAggregationForPart(XElement parent, IElement element)
    {
        if (((ModelElement)element).GetDomainClass().Name == "Part")
        {
            parent.SetAttributeValue("aggregation", "composite");
        }
    }

    public by msdn modified Jan 12, 2015  1217  0  7  0

    IsCompositeAdaptiveStreaming: Determines whether the <see cref="Uri"/> is valid composite smooth streaming uri.

    Determines whether the is valid composite smooth streaming uri. The to be validated. True if [is composite smooth streaming] [the specified URI]; otherwise, false.
    /// <summary>
    /// The extension for the composite smooth streaming file.
    /// </summary>
    private const string CompositeSmoothStreamingExtension = ".CSM";
    
    /// <summary>
    /// Determines whether the <see cref="Uri"/> is valid composite smooth streaming uri.
    /// </summary>
    /// <param name="uri">The <see cref="Uri"/> to be validated.</param>
    /// <returns>
    /// <c>True</c> if [is composite smooth streaming] [the specified URI]; otherwise, <c>false</c>.
    /// </returns>
    public static bool IsCompositeAdaptiveStreaming(Uri uri)
    {
        return uri != null && uri.OriginalString.ToUpper(CultureInfo.InvariantCulture).Contains(CompositeSmoothStreamingExtension);
    }

    public by msdn modified Jan 12, 2015  1060  0  6  0

    AddClipToCompositeManifestInfo: Adds a Clip to a CompositeManifestInfo from the specified Shot.

    Adds a Clip to a CompositeManifestInfo from the specified Shot. The Shot object containing the SubClipItem to use. The manifest stream to calculate the clip positions. The composite manifest info to add the clip.
    /// <summary>
    /// Adds a Clip to a CompositeManifestInfo from the specified Shot.
    /// </summary>
    /// <param name="shot">The Shot object containing the SubClipItem to use.</param>
    /// <param name="manifestStream">The manifest stream to calculate the clip positions.</param>
    /// <param name="compositeManifestInfo">The composite manifest info to add the clip.</param>
    private static void AddClipToCompositeManifestInfo(Shot shot, Stream manifestStream, CompositeManifestInfo compositeManifestInfo)
    {
        const ulong Timescale = 10000000;
    
        ulong startPosition = 0;
    
        SmoothStreamingManifestParser parser = new SmoothStreamingManifestParser(manifestStream);
        manifestStream.Seek(0, SeekOrigin.Begin);
    
        var subClipAsset = shot.Source as SubClipItem;
        var smoothStreamingVideoItem = shot.Source as SmoothStreamingVideoItem;
        var smoothStreamingAudioItem = shot.Source as SmoothStreamingAudioItem;
    
        // the timeline elements holds the in/out position, instead of creating an ISubClipAsset
        double markIn = shot.SourceAnchor.MarkIn.Value;
        double markOut = shot.SourceAnchor.MarkOut.Value;
    
        if (smoothStreamingVideoItem != null || smoothStreamingAudioItem != null)
        {
            startPosition = GetStartPositionFromManifest(parser);
        }
    
        if (!string.IsNullOrEmpty(shot.SequenceAudioStream))
        {
            var audioStreamsToRemove = parser.ManifestInfo.Streams.Where(s => s.StreamType.Equals("Audio", StringComparison.CurrentCultureIgnoreCase) &&
                !s.Attributes["Name"].Equals(shot.SequenceAudioStream)).ToList();
    
            if (audioStreamsToRemove != null)
            {
                foreach (var audioStream in audioStreamsToRemove)
                {
                    parser.ManifestInfo.Streams.Remove(audioStream);
                }
            }
        }
    
        if (subClipAsset != null)
        {
            if (!string.IsNullOrEmpty(subClipAsset.SequenceVideoStream))
            {
                var videoStream = parser.ManifestInfo.Streams.First(s => s.StreamType.Equals("Video", StringComparison.CurrentCultureIgnoreCase));
    
                var qualityLevelsToRemove = videoStream.QualityLevels.Where(q => !q.CustomAttributes.ContainsKey("cameraAngle") ||
                    !q.CustomAttributes["cameraAngle"].Equals(subClipAsset.SequenceVideoStream)).ToList();
    
                foreach (var qualityLevel in qualityLevelsToRemove)
                {
                    videoStream.QualityLevels.Remove(qualityLevel);
                }
            }
    
            startPosition = GetStartPositionFromManifest(parser);
        }
    
        ulong clipBegin = (ulong)((markIn * Timescale) + startPosition);
        ulong clipEnd = (ulong)((markOut * Timescale) + startPosition);
    
        Resource resource = shot.Source.Resources.SingleOrDefault(x => !string.IsNullOrEmpty(x.Ref));
    
        Uri assetUri;
    
        Uri.TryCreate(resource.Ref, UriKind.Absolute, out assetUri);
    
        var customAttributes = new Dictionary<string, string> { { "CMSId", shot.Source.CMSId }, { "AzureId", shot.Source.AzureId } };
        compositeManifestInfo.AddClip(assetUri, clipBegin, clipEnd, customAttributes, parser.ManifestInfo);
    }

    public by msdn modified Jan 12, 2015  1056  0  6  0

    WriteClip: Writes Clip element.

    Writes Clip element. The writer where the Clip is being written. The clip information to write. Defines whether if the composite manifest should be compressed. Defines the minimum bitrate for the quality levels. Defines the maximum bitrate for the quality levels. Specifies if only one quality level should be generated. Specifies if the r
    /// <summary>
    /// Writes Clip element.
    /// </summary>
    /// <param name="writer">The writer where the Clip is being written.</param>
    /// <param name="clip">The clip information to write.</param>
    /// <param name="compressManifest">Defines whether if the composite manifest should be compressed.</param>
    /// <param name="minBitrate">Defines the minimum bitrate for the quality levels.</param>
    /// <param name="maxBitrate">Defines the maximum bitrate for the quality levels.</param>
    /// <param name="isSingleBitrate">Specifies if only one quality level should be generated.</param>
    /// <param name="onlyAudioAndVideoTracks">Specifies if the resulting manifest should include video and audio tracks only.</param>
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope",
        Justification = "It's already being done. There's a finally block in place that disposes of the stream.")]
    private static void WriteClip(XmlWriter writer, Clip clip, bool compressManifest, long minBitrate, long maxBitrate, bool isSingleBitrate, bool onlyAudioAndVideoTracks)
    {
        ulong? chunkEndPositionTime = null;
    
        StringBuilder output = new StringBuilder();
        XmlWriter tempWriter = default(XmlWriter);
    
        try
        {
            tempWriter = CreateWriter(output, true, true);
    
            if (tempWriter != null)
            {
                var streamsToWrite = onlyAudioAndVideoTracks
                    ? clip.Streams.Where(s => s.StreamType.Equals("video", StringComparison.OrdinalIgnoreCase) || s.StreamType.Equals("audio", StringComparison.OrdinalIgnoreCase))
                    : clip.Streams;
    
                foreach (StreamInfo streamInfo in streamsToWrite)
                {
                    XmlWriter chunkWriter = default(XmlWriter);
                    StringBuilder chunkOutput = new StringBuilder();
    
                    bool allChunksAreTimeBased = streamInfo.Chunks.All(c => c.Time.HasValue);
    
                    try
                    {
                        IList<Chunk> chunks = new List<Chunk>();
                        int numberOfChunks = 0;
                        chunkWriter = CreateWriter(chunkOutput, true, true);
                        if (chunkWriter != null)
                        {
                            ulong comparisonTime = 0;
                            int? chunkBeginPositionIndex = null;
                            Chunk[] populatedChunks = GetChunksWithPopulatedTimestamp(streamInfo);
    
                            for (int i = 0; i < streamInfo.Chunks.Count; i++)
                            {
                                ulong tempComparisonTime = 0;
    
                                Chunk chunk = streamInfo.Chunks[i];
    
                                if (chunk.Time.HasValue)
                                {
                                    tempComparisonTime = chunk.Time.Value;
                                }
                                else
                                {
                                    ulong prevChunkDuration = (i > 0)
                                                                  ? streamInfo.Chunks[i - 1].Duration.GetValueOrDefault()
                                                                  : 0;
    
                                    ulong prevChunkTime = (i > 0)
                                                                  ? streamInfo.Chunks[i - 1].Time.GetValueOrDefault()
                                                                  : 0;
    
                                    tempComparisonTime = comparisonTime + prevChunkDuration;
                                }
    
                                comparisonTime = tempComparisonTime;
    
                                if (tempComparisonTime >= clip.ClipBegin && tempComparisonTime <= clip.ClipEnd)
                                {
                                    comparisonTime = tempComparisonTime;
    
                                    bool chunkWritten = false;
    
                                    if (chunkBeginPositionIndex == null)
                                    {
                                        if (i > 0 || (i == 0 && tempComparisonTime > clip.ClipBegin))
                                        {
                                            chunkBeginPositionIndex = (i > 0) ? i - 1 : 0;
    
                                            if (chunk.Time.HasValue && chunk.Time.Value > clip.ClipBegin)
                                            {
                                                Chunk previousChunk = populatedChunks[chunkBeginPositionIndex.Value];
    
                                                ulong newTime = previousChunk.Time
                                                                ?? comparisonTime + previousChunk.Duration.GetValueOrDefault();
    
                                                int index = i == 0 ? i + 1 : i;
    
                                                ulong? duration = chunk.Duration
                                                                  ??
                                                                  ((streamInfo.Chunks.Count
                                                                    > chunkBeginPositionIndex)
                                                                       ? streamInfo.Chunks[index].Time - newTime
                                                                       : 0);
    
                                                WriteChunk(chunkWriter, new Chunk(null, newTime, duration));
                                                numberOfChunks++;
    
                                                chunkWritten = true;
                                            }
                                            else if (chunk.Duration.HasValue && comparisonTime > clip.ClipBegin)
                                            {
                                                ulong prevChunkDuration = (i > 0)
                                                                              ? streamInfo.Chunks[i - 1].Duration.GetValueOrDefault()
                                                                              : 0;
                                                ulong newTime = comparisonTime - prevChunkDuration;
    
                                                WriteChunk(chunkWriter, new Chunk(null, newTime, prevChunkDuration));
                                                numberOfChunks++;
    
                                                chunkWritten = true;
                                            }
                                        }
                                        else
                                        {
                                            chunkBeginPositionIndex = i;
                                        }
                                    }
    
                                    int chunkEndPositionIndex = i;
    
                                    if (i == 0 && chunkBeginPositionIndex == 0 && chunkWritten)
                                    {
                                        continue;
                                    }
    
                                    ulong? chunkDuration = null;
    
                                    if (chunkEndPositionIndex == streamInfo.Chunks.Count - 1)
                                    {
                                        chunkDuration = chunk.Duration;
                                        Chunk lastChunk = streamInfo.Chunks[chunkEndPositionIndex];
    
                                        if (lastChunk.Time.HasValue)
                                        {
                                            chunkEndPositionTime = lastChunk.Time;
                                        }
                                        else if (lastChunk.Duration.HasValue)
                                        {
                                            chunkEndPositionTime = comparisonTime + lastChunk.Duration;
                                        }
                                    }
    
                                    if (!chunkDuration.HasValue)
                                    {
                                        Chunk lastChunk = streamInfo.Chunks[chunkEndPositionIndex];
    
                                        if (lastChunk.Time.HasValue)
                                        {
                                            ulong? duration = streamInfo.Chunks[chunkEndPositionIndex + 1].Time
                                                              - lastChunk.Time;
    
                                            chunkDuration = duration;
    
                                            if (chunkDuration == null && lastChunk.Duration.HasValue)
                                            {
                                                chunkDuration = lastChunk.Duration.Value;
                                            }
    
                                            if (lastChunk.Time + duration >= clip.ClipEnd)
                                            {
                                                tempComparisonTime = lastChunk.Time.GetValueOrDefault()
                                                                     + duration.GetValueOrDefault();
                                            }
                                        }
                                        else if (lastChunk.Duration.HasValue)
                                        {
                                            // moved from the below 'if' to here to enable support for d-based manifests
                                            chunkDuration = lastChunk.Duration.Value;
    
                                            if (comparisonTime + lastChunk.Duration >= clip.ClipEnd)
                                            {
                                                tempComparisonTime = comparisonTime
                                                                     + lastChunk.Duration.GetValueOrDefault();
                                            }
                                        }
                                    }
    
                                    ulong? time;
    
                                    if (numberOfChunks > 0 && chunk.Time.HasValue && chunk.Duration.HasValue)
                                    {
                                        time = chunk.Time.Value;
                                    }
                                    else
                                    {
                                        // should use t={time} when the chunk is the first one or it specifies a t (for example looping manifests)
                                        time = (numberOfChunks == 0)
                                                      || (chunk.Time.HasValue && !allChunksAreTimeBased)
                                                          ? comparisonTime
                                                          : (ulong?)null;
                                    }
    
                                    Chunk currentChunk = new Chunk(null, time, chunkDuration);
    
                                    if (compressManifest)
                                    {
                                        if (chunks.Count == 0)
                                        {
                                            chunks.Add(currentChunk);
                                        }
                                        else
                                        {
                                            Chunk lastChunk = chunks[chunks.Count - 1];
    
                                            if (lastChunk.Duration == currentChunk.Duration)
                                            {
                                                lastChunk.Repeat++;
                                            }
                                            else
                                            {
                                                chunks.Add(currentChunk);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        WriteChunk(chunkWriter, currentChunk);
                                    }
    
                                    numberOfChunks++;
                                }
    
                                if (tempComparisonTime >= clip.ClipEnd)
                                {
                                    if (!chunkEndPositionTime.HasValue)
                                    {
                                        chunkEndPositionTime = clip.ClipEnd;
                                    }
    
                                    break;
                                }
                            }
    
                            if (compressManifest)
                            {
                                foreach (Chunk chunk in chunks)
                                {
                                    WriteChunk(chunkWriter, chunk);
                                }
                            }
    
                            streamInfo.Attributes["Chunks"] = numberOfChunks.ToString(CultureInfo.InvariantCulture);
                        }
                    }
                    finally
                    {
                        if (chunkWriter != null)
                        {
                            chunkWriter.Dispose();
                        }
                    }
    
                    WriteStreamIndex(tempWriter, streamInfo, false, minBitrate, maxBitrate, isSingleBitrate);
                    tempWriter.WriteRaw(Environment.NewLine);
                    tempWriter.WriteRaw(chunkOutput.ToString());
                    tempWriter.WriteRaw(Environment.NewLine);
                    tempWriter.WriteEndElement();
                }
            }
        }
        finally
        {
            if (tempWriter != null)
            {
                tempWriter.Dispose();
            }
        }
    
        writer.WriteStartElement("Clip");
        writer.WriteAttributeString("Url", clip.Url.ToString());
        writer.WriteAttributeString("ClipBegin", clip.ClipBegin.ToString(CultureInfo.InvariantCulture));
        writer.WriteAttributeString("ClipEnd", clip.ClipEnd.ToString(CultureInfo.InvariantCulture));
    
        foreach (var customAttibute in clip.CustomAttributes)
        {
            if (!string.IsNullOrWhiteSpace(customAttibute.Key) && !string.IsNullOrWhiteSpace(customAttibute.Value))
            {
                writer.WriteAttributeString(customAttibute.Key, customAttibute.Value);
            }
        }
    
        writer.WriteRaw(Environment.NewLine);
        writer.WriteRaw(output.ToString());
        writer.WriteRaw(Environment.NewLine);
        writer.WriteEndElement();
    }

    external by Github modified Dec 31, 2015  274  0  3  0

    Through friends http://www.dgtresearch.com/ventolin-hfa-bodybuilding.pptx composite wishing generic ventolin salbutamol obat fourteenth employer The world&#8217;s largest car market, China, with a population of 1.3 billion people and an emerging middl...

    Through friends http://www.dgtresearch.com/ventolin-hfa-bodybuilding.pptx composite wishing generic ventolin salbutamol obat fourteenth employer The world&#8217;s largest car market, China, with a population of 1.3 billion people and an emerging middle class, holds great potential for investors and consumers alike with annual growth rates in the a
    Through friends http://www.dgtresearch.com/ventolin-hfa-bodybuilding.pptx composite wishing generic ventolin salbutamol obat fourteenth employer  The world&#8217;s largest car market, China, with a population of 1.3 billion people and an emerging middle class, holds great potential for investors and consumers alike with annual growth rates in the auto sector expected to hold at around 23 percent to 2017, according to Alliance Bernstein Asset Managers.
     http://rioartesmanuais.com.br/imitrex-discount-coupons-msp.pptx smelt lizard cost imitrex shot htc pull  When the boy got his hand caught in the pool drain, his aunt and a housekeeper were unable to pull him loose. Finally, two men who had been working in the home intervened, pulled him out and performed CPR.
     
    
    

    external by Manos Psychogyiopoulos modified Dec 18, 2015  255  0  3  0

    Use this snippet to make Composite order line items require processing. Prevents orders with empty Composites from going straight to "Completed" order status.

    Use this snippet to make Composite order line items require processing. Prevents orders with empty Composites from going straight to "Completed" order status.: woocommerce-composites-require-processing.php
    <?php
    /**
     * Plugin Name: WooCommerce Composite Products - Composite Products Require Processing
     * Plugin URI: http://www.woothemes.com/products/composite-products/
     * Description: Use this snippet to make Composite order line items require processing. Prevents orders with empty Composites from going straight to "Completed" order status.
     * Version: 1.0
     * Author: SomewhereWarm
     * Author URI: http://www.somewherewarm.net/
     * Developer: Manos Psychogyiopoulos
     *
     * Requires at least: 3.8
     * Tested up to: 4.0
     *
     * Copyright: © 2014 Manos Psychogyiopoulos (psyx@somewherewarm.net).
     * License: GNU General Public License v3.0
     * License URI: http://www.gnu.org/licenses/gpl-3.0.html
     */
    // To use this snippet, download this file into your plugins directory and activate it, or copy the code under this line into the functions.php file of your (child) theme.
    
    add_action( 'woocommerce_pre_payment_complete', 'wc_cp_composites_require_processing' );
    
    function wc_cp_composites_require_processing( $order_id ) {
    
    	remove_filter( 'woocommerce_order_item_needs_processing', array( WC_CP()->order, 'wc_cp_container_items_need_no_processing' ), 10, 3 );
    }
    
    

    external by Yuya Tanaka modified Jun 27, 2015  116  0  3  0

    .lift(CompositeSubscriptions.attachTo(mCompositeSubscription)) and forget about subscriptions but composite one.

    .lift(CompositeSubscriptions.attachTo(mCompositeSubscription)) and forget about subscriptions but composite one.: CompositeSubscriptions.java
    import rx.Observable;
    import rx.Subscriber;
    import rx.functions.Action0;
    import rx.subscriptions.CompositeSubscription;
    import rx.subscriptions.Subscriptions;
    
    public class CompositeSubscriptions {
        /**
         * Automatically adds to / removes from specified {@link CompositeSubscription} when subscribe / unsubscribe is called.
         * Useful when subscribing observable repeatedly, as you do not need to manipulate CompositeSubscription manually.
         */
        public static <T> Observable.Operator<T, T> attachTo(CompositeSubscription compositeSubscription) {
            return new Observable.Operator<T, T>() {
                @Override
                public Subscriber<? super T> call(Subscriber<? super T> subscriber) {
                    compositeSubscription.add(subscriber);
                    subscriber.add(Subscriptions.create(new Action0() {
                        @Override
                        public void call() {
                            compositeSubscription.remove(subscriber);
                        }
                    }));
                    return subscriber;
                }
            };
        }
    }
    
    
    
    • Public Snippets
    • Channels Snippets