public Stream DownloadPreview(string userId, string id, PreviewSize size, long?version)
        {
            var webRequest = CreatePreviewDocumentRequest(userId, id, size, version);

            webRequest.Timeout = PREVIEW_TIMEOUT;

            HttpWebResponse webResponse = null;

            try
            {
                webResponse = (HttpWebResponse)webRequest.GetResponse();
            }
            catch (WebException e) when((e.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound)
            {
                throw new NotFoundException(e.Message, e);
            }
            catch (WebException e) when((e.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotAcceptable)
            {
                throw new NotAcceptableException(e.Message, e);
            }

            if (webResponse.StatusCode != HttpStatusCode.OK)
            {
                throw new RestClientException("Cannot download preview for document '" + id + "', received status code " + webResponse.StatusCode + ".");
            }

            return(DocumentStreamUtils.WrapDownloadStream(webResponse.GetResponseStream(), streamWrapper));
        }
Exemple #2
0
        private void BwTheirDataWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            TheirDataLoaded = false;
            FileInfo theirFileInfo = new FileInfo(theirDataDialog.FileName);

            reader.PopulateTheirDataList(theirFileInfo);

            lbTheirDataPreviewSize.PerformSafely(() => theirPreviewSize = (PreviewSize)lbTheirDataPreviewSize.SelectedIndex);
            UpdateTheirDataPreview(theirPreviewSize);
            TheirDataLoaded = true;
        }
Exemple #3
0
        private void BwOurDataWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            OurDataLoaded = false;
            FileInfo ourFileInfo = new FileInfo(ourDataDialog.FileName);

            reader.ClearOurDataList();
            reader.PopulateOurDataList(ourFileInfo);
            lbTheirDataPreviewSize.PerformSafely(() => ourPreviewSize = (PreviewSize)lbOurDataPreviewSize.SelectedIndex);
            UpdateOurDataPreview(ourPreviewSize);
            OurDataLoaded = true;
        }
Exemple #4
0
        public NodeWindow(Node node)
        {
            this.windowIndex = indexCount;
            indexCount++;

            // cast to specific type
            if(node is GeneratorNode) {
            generatorNode = (GeneratorNode)node;
            type = WINDOWTYPE.GENERATOR;
            node.title = generatorNode.type.ToString();
            }
            if(node is OperatorNode){
            operatorNode = (OperatorNode)node;
            type = WINDOWTYPE.OPERATOR;
            node.title = operatorNode.type.ToString();
            }
            if(node is OutputNode) {
            outputNode = (OutputNode)node;
            type = WINDOWTYPE.OUTPUT;
            previewSize = PreviewSize.x2;
            }
            if(node is MacroNode) {
            macroNode = (MacroNode)node;
            type = WINDOWTYPE.MACRO;
            }
            if(node is TextureNode) {
            textureNode = (TextureNode)node;
            type = WINDOWTYPE.TEXTURE;
            }
            if(node is ColorNode) {
            colorNode = (ColorNode)node;

            gradient = new GradientWrapper();
            gradient.GradientData = colorNode.gradient;

            type = WINDOWTYPE.COLOR;
            }

            // also save general reference
            this.node = node;

            // random connection color
            connectionColor = new Color(Random.Range(100, 200) / 255f, Random.Range(100, 200) / 255f, Random.Range(100, 200) / 255f);

            UpdatePreview();
            node.rect.height = controlHeight + (int)previewSize;
            node.rect.width = (int)previewSize + 20;
            if(node.rect.width < 200)
            node.rect.width = 200;

            if(showOutputOptions)
            showOutputOptions = false;
        }
Exemple #5
0
        private void UpdateTheirDataPreview(PreviewSize previewSize)
        {
            int newSize;

            switch (previewSize)
            {
            case PreviewSize.None: newSize = 0; break;

            case PreviewSize.Hundred: newSize = 100; break;

            case PreviewSize.Thousand: newSize = 1000; break;

            case PreviewSize.TenThousand: newSize = 10000; break;

            case PreviewSize.HundredThousand: newSize = 100000; break;

            case PreviewSize.All: newSize = int.MaxValue; break;

            default: newSize = 0; break;
            }

            dgvTheirData.PerformSafely(() => dgvTheirData.Columns.Clear());
            foreach (var header in reader.TheirHeaders)
            {
                dgvTheirData.PerformSafely(() =>
                                           dgvTheirData.Columns.Add(header.Replace(" ", ""), header));
            }

            dgvTheirData.PerformSafely(() => dgvTheirData.Rows.Clear());
            for (int i = 0; i < newSize && i < reader.TheirDataList.Count; i++)
            {
                if (bwTheirDataPreviewWorker.CancellationPending)
                {
                    break;
                }

                // cast to the correct type
                var data = reader.TheirDataList[i] as TheirClickAndImpressionData;
                dgvTheirData.PerformSafely(() =>
                                           dgvTheirData.Rows.Add(
                                               data.IndexString,
                                               data.Clicks,
                                               data.Impressions,
                                               data.DateStamp.ToShortDateString()));
            }
        }
Exemple #6
0
        private void UpdateOurDataPreview(PreviewSize previewSize)
        {
            int newSize;

            switch (previewSize)
            {
            case PreviewSize.None: newSize = 0; break;

            case PreviewSize.Hundred: newSize = 100; break;

            case PreviewSize.Thousand: newSize = 1000; break;

            case PreviewSize.TenThousand: newSize = 10000; break;

            case PreviewSize.HundredThousand: newSize = 100000; break;

            case PreviewSize.All: newSize = int.MaxValue; break;

            default: newSize = 0; break;
            }

            dgvOurData.PerformSafely(() => dgvOurData.Columns.Clear());
            foreach (var header in reader.OurHeaders)
            {
                dgvOurData.PerformSafely(() =>
                                         dgvOurData.Columns.Add(header.Replace(" ", ""), header));
            }

            dgvOurData.PerformSafely(() => dgvOurData.Rows.Clear());
            for (int i = 0; i < newSize && i < reader.OurDataList.Count; i++)
            {
                if (bwOurDataPreviewWorker.CancellationPending)
                {
                    break;
                }

                // cast to the correct type
                var data = reader.OurDataList[i] as OurNameAndTrackingIdData;
                dgvOurData.PerformSafely(() =>
                                         dgvOurData.Rows.Add(
                                             data.ID,
                                             data.Name,
                                             data.TrackingID));
            }
        }
Exemple #7
0
    public NodeWindow(Node node)
    {
        this.windowIndex = indexCount;
        indexCount++;

        // cast to specific type
        if (node is GeneratorNode)
        {
            generatorNode = (GeneratorNode)node;
            type          = WINDOWTYPE.GENERATOR;
        }
        if (node is OperatorNode)
        {
            operatorNode = (OperatorNode)node;
            type         = WINDOWTYPE.OPERATOR;
        }
        if (node is OutputNode)
        {
            outputNode  = (OutputNode)node;
            type        = WINDOWTYPE.OUTPUT;
            previewSize = PreviewSize.x4;
            //autoGeneratePreview = false;
        }
        if (node is MacroNode)
        {
            macroNode = (MacroNode)node;
            type      = WINDOWTYPE.MACRO;
        }

        // also save general reference
        this.node = node;

        // random connection color
        connectionColor = new Color(Random.Range(100, 200) / 255f, Random.Range(100, 200) / 255f, Random.Range(100, 200) / 255f);

        preview          = Generate((int)previewSize);
        node.rect.height = controlHeight + (int)previewSize;
        node.rect.width  = (int)previewSize + 20;
        if (node.rect.width < 200)
        {
            node.rect.width = 200;
        }
    }
Exemple #8
0
    public void DoGUI(int id)
    {
        bool generate = false;

        node.rect.height = (int)previewSize;
        node.rect.width  = (int)previewSize + 70;
        if (node.rect.width < 160)
        {
            node.rect.width = 160;
        }

        GUILayout.BeginArea(new Rect(5f, 20f, node.rect.width - 10, 1000f));

        // preview image
        GUILayout.BeginHorizontal();
        GUILayout.Box(preview);
        GUILayout.BeginVertical();

        if (GUILayout.Button("Update", EditorStyles.miniButton, GUILayout.Width(50)))
        {
            generate = true;
        }

        EditorGUILayout.LabelField("Preview:", EditorStyles.miniLabel, GUILayout.Width(50));
        previewSize = (PreviewSize)EditorGUILayout.EnumPopup(previewSize, GUILayout.Width(50));

        viewControls = EditorGUILayout.Foldout(viewControls, "");
        if (viewControls)
        {
            EditorGUILayout.LabelField("Zoom:", EditorStyles.miniLabel, GUILayout.Width(50));
            zoom = GUILayout.HorizontalSlider(zoom, 1f, .1f, GUILayout.Width(50));
            EditorGUILayout.LabelField("Translate:", EditorStyles.miniLabel);
            tx = GUILayout.HorizontalSlider(tx, 0f, 1f, GUILayout.Width(50));
            ty = GUILayout.HorizontalSlider(ty, 0f, 1f, GUILayout.Width(50));

            node.rect.height += controlHeight * 3f;
        }

        GUILayout.EndVertical();
        GUILayout.EndHorizontal();

        GUILayout.Label("Value range: " + minValue.ToString("0.0") + " to " + maxValue.ToString("0.0"), EditorStyles.miniLabel);

        switch (type)
        {
        case WINDOWTYPE.GENERATOR:
            GeneratorGUI();
            break;

        case WINDOWTYPE.OPERATOR:
            OperatorGUI();
            break;

        case WINDOWTYPE.OUTPUT:
            OutputGUI();
            break;

        case WINDOWTYPE.MACRO:
            MacroGUI();
            break;
        }

        //autoGeneratePreview = GUILayout.Toggle(autoGeneratePreview, "Auto-generate:");

        node.rect.height += controlHeight * 1.5f;

        // generation
        if (generate || (GUI.changed && autoGeneratePreview))
        {
            preview = Generate((int)previewSize);
        }

        GUILayout.EndArea();
        GUI.DragWindow();
    }
Exemple #9
0
        public void DoGUI(int id)
        {
            bool generate = false;

            node.rect.height =  (int)previewSize;
            node.rect.width = (int)previewSize + 70;
            if(node.rect.width < 160)
            node.rect.width = 160;

            //GUILayout.BeginArea(new Rect(5f, 20f, node.rect.width - 10, 1000f));

            // preview image
            GUILayout.BeginHorizontal();
            GUILayout.Box(preview);
            GUILayout.BeginVertical();

            if(GUILayout.Button("Update", EditorStyles.miniButton, GUILayout.Width(50))) {
            generate = true;
            }

            EditorGUILayout.LabelField("Preview:", EditorStyles.miniLabel, GUILayout.Width(50));
            previewSize = (PreviewSize)EditorGUILayout.EnumPopup(previewSize, GUILayout.Width(50));

            viewControls = EditorGUILayout.Foldout(viewControls, "Preview");
            if(viewControls) {
            EditorGUILayout.LabelField("Zoom:", EditorStyles.miniLabel, GUILayout.Width(50));
            zoom = GUILayout.HorizontalSlider(zoom, 1f, .1f, GUILayout.Width(50));
            EditorGUILayout.LabelField("Translate:", EditorStyles.miniLabel);
            tx = GUILayout.HorizontalSlider(tx, 0f, 1f, GUILayout.Width(50));
            ty = GUILayout.HorizontalSlider(ty, 0f, 1f, GUILayout.Width(50));

            globalMapPreview = GUILayout.Toggle(globalMapPreview, "Global map");

            node.rect.height += controlHeight * 4f;
            }

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            if(module != null)
            GUILayout.Label("Value range: " + module.minValue.ToString("0.0") + " to " + module.maxValue.ToString("0.0"), EditorStyles.miniLabel);

            switch(type) {
            case WINDOWTYPE.GENERATOR:
            GeneratorGUI();
            break;
            case WINDOWTYPE.OPERATOR:
            OperatorGUI();
            break;
            case WINDOWTYPE.OUTPUT:
            OutputGUI();
            break;
            case WINDOWTYPE.MACRO:
            MacroGUI();
            break;
            case WINDOWTYPE.TEXTURE:
            TextureGUI();
            break;
            case WINDOWTYPE.COLOR:
            ColorGUI();
            break;
            }

            //autoGeneratePreview = GUILayout.Toggle(autoGeneratePreview, "Auto-generate:");

            node.rect.height += controlHeight * 1.5f;

            // showOutputOptions
            /*showOutputOptions = EditorGUILayout.Foldout(showOutputOptions, "Output options");
            node.rect.height += controlHeight / 2;

            if(showOutputOptions) {
            if(node != null) {
                EditorGUILayout.LabelField("Normalize");
                node.normalizeOutput = EditorGUILayout.Toggle(node.normalizeOutput);
                node.rect.height += controlHeight;
                if(node.normalizeOutput) {
                    EditorGUILayout.LabelField("0-1 range");
                    node.zeroToOneRange = EditorGUILayout.Toggle(node.zeroToOneRange);
                    node.rect.height += controlHeight;
                }
            }
            else
                Debug.Log("Module is null");
            }*/

            // generation
            if(generate || (GUI.changed && autoGeneratePreview)) {
            node.SetOutputOptions();
            UpdatePreview();
            }

            //GUILayout.EndArea();
            GUI.DragWindow();
        }
 public static string ToApiParameter(this PreviewSize size)
 {
     return (int)size + "x" + (int)size;
 }
Exemple #11
0
 private void lbOurDataPreviewSize_SelectedIndexChanged(object sender, EventArgs e)
 {
     OurPreviewSize = (PreviewSize)lbOurDataPreviewSize.SelectedIndex;
 }
Exemple #12
0
        public NodeWindow(Node node)
        {
            this.windowIndex = indexCount;
            indexCount++;

            // cast to specific type
            if (node is GeneratorNode)
            {
                generatorNode = (GeneratorNode)node;
                type          = WINDOWTYPE.GENERATOR;
                node.title    = generatorNode.type.ToString();
            }
            if (node is OperatorNode)
            {
                operatorNode = (OperatorNode)node;
                type         = WINDOWTYPE.OPERATOR;
                node.title   = operatorNode.type.ToString();
            }
            if (node is OutputNode)
            {
                outputNode  = (OutputNode)node;
                type        = WINDOWTYPE.OUTPUT;
                previewSize = PreviewSize.x2;
            }
            if (node is MacroNode)
            {
                macroNode = (MacroNode)node;
                type      = WINDOWTYPE.MACRO;
            }
            if (node is TextureNode)
            {
                textureNode = (TextureNode)node;
                type        = WINDOWTYPE.TEXTURE;
            }
            if (node is ColorNode)
            {
                colorNode = (ColorNode)node;

                if (colorNode.gradient == null)
                {
                    colorNode.gradient = new Gradient();
                    if (colorNode.gradientColorKeys != null)
                    {
                        colorNode.gradient.colorKeys = SerializableGradientColorKey.ToGradientColorKeys(colorNode.gradientColorKeys);
                        colorNode.gradient.alphaKeys = SerializableGradientAlphaKey.ToGradientColorKeys(colorNode.gradientAlphaKeys);
                    }
                    gradient = new GradientWrapper();
                    gradient.GradientData = colorNode.gradient;
                }

                type = WINDOWTYPE.COLOR;
            }

            // also save general reference
            this.node = node;

            // random connection color
            connectionColor = new Color(Random.Range(100, 200) / 255f, Random.Range(100, 200) / 255f, Random.Range(100, 200) / 255f);

            UpdatePreview();
            node.rect.height = controlHeight + (int)previewSize;
            node.rect.width  = (int)previewSize + 20;
            if (node.rect.width < 200)
            {
                node.rect.width = 200;
            }
        }
Exemple #13
0
        public void DoGUI(int id)
        {
            bool generate = false;

            node.rect.height = (int)previewSize;
            node.rect.width  = (int)previewSize + 70;
            if (node.rect.width < 160)
            {
                node.rect.width = 160;
            }

            //GUILayout.BeginArea(new Rect(5f, 20f, node.rect.width - 10, 1000f));

            // preview image
            GUILayout.BeginHorizontal();
            GUILayout.Box(preview);
            GUILayout.BeginVertical();

            if (GUILayout.Button("Update", EditorStyles.miniButton, GUILayout.Width(50)))
            {
                generate = true;
            }

            EditorGUILayout.LabelField("Preview:", EditorStyles.miniLabel, GUILayout.Width(50));
            previewSize = (PreviewSize)EditorGUILayout.EnumPopup(previewSize, GUILayout.Width(50));

            viewControls = EditorGUILayout.Foldout(viewControls, "Preview");
            if (viewControls)
            {
                EditorGUILayout.LabelField("Zoom:", EditorStyles.miniLabel, GUILayout.Width(50));
                zoom = GUILayout.HorizontalSlider(zoom, 1f, .1f, GUILayout.Width(50));
                EditorGUILayout.LabelField("Translate:", EditorStyles.miniLabel);
                tx = GUILayout.HorizontalSlider(tx, 0f, 1f, GUILayout.Width(50));
                ty = GUILayout.HorizontalSlider(ty, 0f, 1f, GUILayout.Width(50));

                globalMapPreview = GUILayout.Toggle(globalMapPreview, "Global map");

                node.rect.height += controlHeight * 4f;
            }

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            if (module != null)
            {
                GUILayout.Label("Value range: " + module.minValue.ToString("0.0") + " to " + module.maxValue.ToString("0.0"), EditorStyles.miniLabel);
            }

            switch (type)
            {
            case WINDOWTYPE.GENERATOR:
                GeneratorGUI();
                break;

            case WINDOWTYPE.OPERATOR:
                OperatorGUI();
                break;

            case WINDOWTYPE.OUTPUT:
                OutputGUI();
                break;

            case WINDOWTYPE.MACRO:
                MacroGUI();
                break;

            case WINDOWTYPE.TEXTURE:
                TextureGUI();
                break;

            case WINDOWTYPE.COLOR:
                ColorGUI();
                break;
            }

            //autoGeneratePreview = GUILayout.Toggle(autoGeneratePreview, "Auto-generate:");

            node.rect.height += controlHeight * 1.5f;

            // showOutputOptions

            /*showOutputOptions = EditorGUILayout.Foldout(showOutputOptions, "Output options");
             * node.rect.height += controlHeight / 2;
             *
             * if(showOutputOptions) {
             *      if(node != null) {
             *              EditorGUILayout.LabelField("Normalize");
             *              node.normalizeOutput = EditorGUILayout.Toggle(node.normalizeOutput);
             *              node.rect.height += controlHeight;
             *              if(node.normalizeOutput) {
             *                      EditorGUILayout.LabelField("0-1 range");
             *                      node.zeroToOneRange = EditorGUILayout.Toggle(node.zeroToOneRange);
             *                      node.rect.height += controlHeight;
             *              }
             *      }
             *      else
             *              Debug.Log("Module is null");
             * }*/

            // generation
            if (generate || (GUI.changed && autoGeneratePreview))
            {
                node.SetOutputOptions();
                UpdatePreview();
            }

            //GUILayout.EndArea();
            GUI.DragWindow();
        }
        private HttpWebRequest CreatePreviewDocumentRequest(string userId, string id, PreviewSize size, long?version)
        {
            var path = URI_RESOURCE + id;

            if (version != null)
            {
                path += ";" + RestApiConstants.VERSION + "=" + version;
            }
            path += ";preview=" + size.ToApiParameter() + ";pages=1?wait-for-generation=10&include-error-info=false";

            HttpWebRequest httpWebRequest = CreateDownloadRequest(userId, null, new Uri(new Uri(GetBaseAddress()), path));

            httpWebRequest.Accept = "image/png, image/jpeg";
            return(httpWebRequest);
        }