public bool HandleResult( IResult result, IFormatInfo outputFormat, HttpRequestBase request, HttpResponseBase response )
        {
            response.AddHeader("Accept-Ranges", "bytes");

            Range range;
            if ( !TryGetRequestedRange( request, out range ) )
            {
                return false;
            }

            if (!ValidateIfRangeHeader(request, result))
            {
                return false;
            }

            var offset = range.Start ?? 0;
            var end = range.End.HasValue ? range.End.Value : result.ContentLength - 1;
            var length = end - offset + 1;

            response.AddHeader( "Content-Range", "bytes " + offset + "-" + end + "/" + result.ContentLength );
            response.StatusCode = 206;

            result.Serve( response, offset, length );
            return true;
        }
Example #2
0
 void AuthCallBack(IResult result)
 {
     if (result.Error != null)
     {
         // display error popup
         popup.SetActive(true);
         newGame.enabled = true;
         loadGame.enabled = true;
         rulesButton.enabled = true;
     }
     else
     {
         if (FB.IsLoggedIn)
         {
             FB.API("/me?fields=first_name,last_name", HttpMethod.GET, DisplayUsername);
             FB.API("/me/friends?fields=first_name,last_name", HttpMethod.GET, DisplayFriends);
             //FB.API("me/picture?type=square&height=128&width=128", HttpMethod.GET, DisplayProfilePic);
             FB.GetAppLink(GetAppLink);
         }
         else
         {
             // display error popup
             popup.SetActive(true);
             newGame.enabled = true;
             loadGame.enabled = true;
             rulesButton.enabled = true;
         }
     }
 }
        public ContinueResultDecorator(IResult inner, Func<IEnumerable<IResult>> coroutine)
            : base(inner)
        {
            if (coroutine == null) throw new ArgumentNullException("coroutine");

            _coroutine = coroutine;
        }
Example #4
0
        public override IResult Execute(IResult previousResults)
        {
            try
            {
                var request =
                    EndpointManager.GetContract<AbstractIdentityQueryContract>(EndPointFunctions.IdentityQuery);

                request.LoginId = SettingsManager.GetTemporarySettingString(UsernameKey);
                request.Credential1 = SettingsManager.GetTemporarySettingString(PassphraseKey);
                request.Credential2 = SettingsManager.GetTemporarySettingString(Credential2Key);
                request.Credential3 = SettingsManager.GetTemporarySettingString(Credential3Key);
                request.Credential4 = SettingsManager.GetTemporarySettingString(Credential4Key);
                request.Provider = CertificateProvider;
                request.Properties = _properties;
                request.GroupPaths = _groupPaths;

                var result = request.MakeRequest<IdentityQueryResult>();
                if (result == null)
                    return request.GetErrorResult();

                SettingsManager.SetTemporaryObject(UserPropertiesKey, result.Properties);
                SettingsManager.SetTemporaryObject(GroupPathsKey, result.Groups);

                return new NextResult();
            }
            catch (Exception e)
            {
                return new ExceptionOccurred(e);
            }
        }
        public override IResult Execute(IResult previousResults)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(SettingKey))
                    throw new Exception("No settings key specified");

                var info = SettingsManager.GetTemporaryObject(SettingKey) as FileInfoWrapper;
                if (info == null)
                    throw new Exception("Data object is invalid");

                var result = info.VerifyFile(PathUtilities.DownloadFolder);
                if (!result.Result)
                {
                    Log.Warn(result.Reason);
                    return new CouldNotVerifyFile { Target = info.FileName, Issue = result.Reason };
                }

                return new NextResult();
            }
            catch (Exception e)
            {
                return new ExceptionOccurred(e);
            }
        }
Example #6
0
        public void SetUp()
        {
            var path = new[] { "path1, path2 " };

            this.ContentRepository.Stub(r => r.FindContent(path)).Return(null);
            this.result = this.RenderingService.GetPage(path, null, null, false);
        }
        public override IResult Execute(IResult previousResults)
        {
            try
            {
                var startTime = DateTime.UtcNow;
                TimeSpan elapsed;
                do
                {
                    DialogsManager.WaitForDurationOrCancel(DateTime.UtcNow, new TimeSpan(0,0,0,Interval));
                    if (DialogsManager.CancelRequested)
                        break;

                    if (SecurityUtilities.SecurityProviderHealth.Good ==
                        SecurityUtilities.QuerySecurityProviderHealth(Provider))
                        break;

                    elapsed = DateTime.UtcNow.Subtract(startTime);
                } while (elapsed.Duration().TotalSeconds < Duration);

                return new NextResult();
            }
            catch (Exception e)
            {
                return new ExceptionOccurred(e);
            }
        }
Example #8
0
    public void HandleResult(IResult result)
    {
        if (result == null)
        {
            print ( "Null Response\n");
            return;
        }

        // Some platforms return the empty string instead of null.
        if (!string.IsNullOrEmpty(result.Error))
        {
            print("Error Response:\n" + result.Error);
        }
        else if (result.Cancelled)
        {
            print("Cancelled Response:\n" + result.RawResult);
        }
        else if (!string.IsNullOrEmpty(result.RawResult))
        {
            print("Success Response:\n" + result.RawResult);
            getUserData();
        }
        else
        {
            print("Empty Response\n");
        }
    }
Example #9
0
 public IEnumerable<Bitmap> IteratePartsKNN(IResult res, double dqp, float stddev, float mean, Sequence seq)
 {
     var sym = this.Discretize(dqp, stddev, mean);
     yield return seq.Unravel(sym);
     var left = sym - 1;
     var right = sym + 1;
     bool do_next = true;
     while (do_next) {
         do_next = false;
         var __left = this.Discretize(dqp - res.CoveringRadius, stddev, mean);
         if (0 <= left && __left <= left) {
             yield return seq.Unravel(left);
             --left;
             do_next = true;
         }
         var __right = this.Discretize(dqp + res.CoveringRadius, stddev, mean);
         if (right <= __right && right < seq.Sigma) {
             yield return seq.Unravel(right);
             ++right;
             do_next = true;
         }
         /*Console.WriteLine ("left: {0}, right: {1}, __left: {2}, __right: {3}",
                            left, right, __left, __right);*/
     }
 }
Example #10
0
        public override IResult Execute(IResult previousResults)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(ChildDialog))
                    throw new Exception("Child dialog key cannot be null or empty");

                if (string.IsNullOrWhiteSpace(Banner))
                    throw new Exception("Banner key cannot be null or empty");

                var dialog = DialogsManager.GetExistingDialog(ParentDialog);
                if (dialog == null)
                    return new DialogInstanceNotFound { Dialog = ParentDialog };

                var childManager = DialogsManager.GetDialog<BorderedChildDialogModel>(ChildDialog);
                if (childManager == null)
                {
                    return new DialogInstanceNotFound { Dialog = ChildDialog };
                }

                return dialog.ShowChildBannerModal(childManager, Banner);
            }
            catch (Exception e)
            {
                return new ExceptionOccurred(e);
            }
        }
Example #11
0
 //, Result C)
 protected void GreedySearchGlobalMinima(int parent, object q, IResult res)
 {
     var rs = this.SEQ.Unravel (parent);
     var children_count = rs.Count1;
     var closer_dist = double.MaxValue;
     var closer_objID = -1;
     for (int rank = 1; rank <= children_count; ++rank) {
         var objID = rs.Select1(rank);
         var dist = this.DB.Dist(q, this.DB[objID]);
         res.Push (objID, dist);
         if (dist < closer_dist) {
             closer_dist = dist;
             closer_objID = objID;
         }
         //if (C != null) C.Push (objID, dist);
     }
     if (closer_objID >= 0) {
         this.GreedySearchGlobalMinima (closer_objID, q, res); //, C);
     }
     //			for (int childID = 0; childID < children_count; ++childID) {
     //				var child_objID = C[childID];
     //				var child_dist = D[childID];
     //				var radius = res.CoveringRadius;
     //				//Console.WriteLine ("---- cov: {0}", this.COV[child_objID]);
     //				if (child_dist <= radius + this.GetCOV(child_objID) && child_dist <= closer_dist + radius + radius) {
     //					this.SearchKNNNode(child_objID, q, res);
     //                }
     //            }
 }
        public override IResult Execute(IResult previousResults)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(Target))
                    throw new InvalidOperationException("The target path cannot be empty");

                if (!File.Exists(Target))
                    Target = Path.Combine(PathUtilities.DownloadFolder, Target);

                if (!File.Exists(Target))
                    return new FileNotFound { Target = Target };

                var result = CertificateUtilities.ImportUserCertificateFromFile(
                    Target,
                    SettingsManager.GetSecureTemporarySettingString(CredentialsKey));

                if (!result.Result)
                    return new CouldNotImportContent{Issue = result.Reason};

                return new NextResult();
            }
            catch (Exception e)
            {
                return new ExceptionOccurred(e);
            }
        }
        public override IResult Execute(IResult previousResults)
        {
            try
            {
                foreach (var setter in _setters)
                {
                    var key = setter.Key;
                    var value = setter.Value;

                    if (string.IsNullOrWhiteSpace(key))
                    {
                        Log.Warn("Cannot retrieve settings value to user settings; settings key not specified");
                        continue;
                    }

                    var settingsPropertyName = value;
                    if (string.IsNullOrWhiteSpace(settingsPropertyName))
                        settingsPropertyName = key;

                    var settingsValue = Properties.Settings.Default.GetKeyedProperty(settingsPropertyName);
                    SettingsManager.SetTemporarySettingString(key, settingsValue);
                }

                return new NextResult();
            }
            catch (Exception e)
            {
                Log.Warn(e);
                return new NextResult();
            }
        }
Example #14
0
        public override IResult Execute(IResult previousResults)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(SettingKey))
                    throw new Exception("Setting key not specified");

                var request =
                    EndpointManager.GetContract<AbstractLocationQueryContract>(EndPointFunctions.LocationQuery);
                request.IgnoreCertificateErrors = true;
                var result = request.MakeRequest<LocationQueryResult>();
                if (result == null)
                {
                    Log.WarnFormat("An issue occurred while querying server for location data: {0}",
                        request.GetErrorResult().GetDetails());
                    return null;
                }

                SettingsManager.SetTemporarySettingString(SettingKey, result.Location);

                return new NextResult();
            }
            catch (Exception e)
            {
                return new ExceptionOccurred(e);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ContinueResultDecorator"/> class.
        /// </summary>
        /// <param name="result">The result to decorate.</param>
        /// <param name="coroutine">The coroutine to execute when <paramref name="result"/> was canceled.</param>
        public ContinueResultDecorator(IResult result, Func<IEnumerable<IResult>> coroutine)
            : base(result) {
            if (coroutine == null)
                throw new ArgumentNullException("coroutine");

            this.coroutine = coroutine;
        }
Example #16
0
 public async Task<IResult> NegotiatedResult(IRequestContext context, IResult result)
 {
     foreach (var interceptor in _interceptors) {
         result = await interceptor.NegotiatedResult(context, result);
     }
     return result;
 }
Example #17
0
        public override IResult Execute(IResult previousResults)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(Value))
                    throw new Exception("Cannot truncate value; value is empty.");

                if (string.IsNullOrWhiteSpace(SettingKey))
                    throw  new Exception("Setting key cannot be empty");

                if (Length<=0)
                    throw new Exception("Length must be greater than zero");

                var newValue = Value;
                if (Length < Value.Length)
                    newValue = Value.Substring(0, Length);

                SettingsManager.SetTemporarySettingString(SettingKey, newValue);

                return new NextResult();

            }
            catch (Exception e)
            {
                Log.WarnFormat("An exception occurred while attempting to truncate a string: {0}", e.Message);
                return new NextResult();
            }
        }
Example #18
0
        public override IResult Execute(IResult previousResults)
        {
            try
            {
                using (var controller = ServiceUtilities.GetServiceInstance("LanmanServer"))
                {
                    if (controller == null)
                    {
                        if (!ServiceUtilities.IsServiceInfoInRegistry("LanmanServer"))
                            return new ServiceInfoNotInRegistry { ServiceName = "LanmanServer"};

                        return new ServiceInstanceNotAvailable { ServiceName = "LanmanServer" };
                    }

                    var result = Enabled ? EnableService(controller) : DisableService(controller);
                    if (!result.Result)
                        throw  new Exception(result.Reason);

                    return new NextResult();
                }
            }
            catch (Exception e)
            {
                return new ExceptionOccurred(e);
            }
        }
 public override IResult Execute(IResult previousResults)
 {
     try
     {
         var result = SecurityUtilities.QuerySecurityProviderHealth(SecurityUtilities.SecurityProviders.AntiVirus);
         switch (result)
         {
             case SecurityUtilities.SecurityProviderHealth.Good:
                 Log.Info("Windows reports that this computer's anti-virus software is in good health.");
                 return new NextResult();
             case SecurityUtilities.SecurityProviderHealth.NotMonitored:
                 Log.Warn("Windows reports that this computer's anti-virus software is not monitored.");
                 return new AntiVirusHealthNotMonitored();
             case SecurityUtilities.SecurityProviderHealth.Poor:
                 Log.Warn("Windows reports that this computer's anti-virus software is in poor health.");
                 return new AntiVirusHealthPoor();
             case SecurityUtilities.SecurityProviderHealth.Snooze:
                 Log.Warn("Windows reports that this computer's security center is not active.");
                 return new SecurityCenterNotActive();
              default:
                 throw new Exception(string.Format("Could not evaluate anti-virus health: Windows returned unexpected result ({0})",result));
         }
     }
     catch (Exception e)
     {
         return new ExceptionOccurred(e);
     }
 }
Example #20
0
        public override IResult Execute(IResult previousResults)
        {
            try
            {
                var eventData = new LoggingEventData
                    {
                        Level = Event.GetAssociatedLevel(),
                        Message = Message,
                        TimeStamp = DateTime.Now
                    };

                if (eventData.Level == null)
                {
                    Log.Warn("Cannot upload log event; Level is null");
                    return new NextResult();
                }

                if (string.IsNullOrWhiteSpace(eventData.Message))
                    eventData.Message = "[no content]";

                var eventEntry = Asynchronous
                    ? new LoggingEvent(eventData)
                    : new BlockingLoggingEvent(eventData);

                Log.Logger.Log(eventEntry);

                return new NextResult();
            }
            catch (Exception e)
            {
                Log.WarnFormat("An exception occurred while attempting to record a log event: {0}", e.Message);
                return new NextResult();
            }
        }
Example #21
0
        private void ChildCompleted(IResult previous, Exception exception)
        {
            if(exception != null)
            {
                if (exception is CancelResult)
                    OnComplete(null);
                else OnComplete(exception);

                return;
            }

            if(previous != null)
                previous.Completed -= ChildCompleted;

            if(_enumerator.MoveNext())
            {
                try
                {
                    var next = _enumerator.Current;
                    next.Completed += ChildCompleted;
                    next.Execute(_message, _handlingNode);
                }
                catch(Exception ex)
                {
                    OnComplete(ex);
                    return;
                }
            }
            else OnComplete(null);
        }
        public override IResult Execute(IResult previousResults)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(Archive))
                    throw new Exception("The archive parameter cannot be null or empty");

                if (string.IsNullOrWhiteSpace(Icon))
                    throw new Exception("The icon parameter cannot be null or empty");

                if (!File.Exists(Archive))
                    return new FileNotFound { Target = Archive };

                var trustedResult = CertificateUtilities.IsFileTrusted(Archive);
                if (!trustedResult.Result)
                    return new CouldNotImportContent { Issue = trustedResult.Reason };

                var bytes = CabArchiveUtilities.ExtractFile(Archive, Icon);
                if (bytes == null)
                    throw new Exception(string.Format("Could not extract {0} from archive", Icon));

                using (var stream = new MemoryStream(bytes))
                    AppearanceManager.ApplicationIcon = BitmapFrame.Create(stream);

                return new NextResult();
            }
            catch (Exception e)
            {
                return new ExceptionOccurred(e);
            }
        }
        private static bool ValidateLastModifyDate(string ifModifiedSinceHeader, IResult result)
        {
            if (string.IsNullOrEmpty(ifModifiedSinceHeader))
            {
                return true;
            }

            if (!result.LastModified.HasValue)
            {
                return false;
            }

            DateTime modifiedSince;
            if (string.IsNullOrEmpty(ifModifiedSinceHeader) || !DateTime.TryParse(ifModifiedSinceHeader, out modifiedSince))
            {
                return false;
            }

            if (modifiedSince <= result.LastModified.Value.Subtract(TimeSpan.FromSeconds(1)))
            {
                return false;
            }

            return true;
        }
        public override IResult Execute(IResult previousResults)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(ObjectKey))
                    throw new Exception("Object key cannot be null");

                if (string.IsNullOrWhiteSpace(SettingsKey))
                    throw new Exception("Setting key cannot be null");

                if (string.IsNullOrWhiteSpace(BaseText))
                    BaseText = "{0}";

                var updateCollection = SettingsManager.GetTemporaryObject(ObjectKey) as UpdateCollection;
                if (updateCollection == null)
                    throw  new Exception("Update collection not present");

                SettingsManager.SetTemporarySettingString(SettingsKey, string.Format(BaseText, updateCollection.Count));

                return new NextResult();
            }
            catch (Exception e)
            {
                return new ExceptionOccurred(e);
            }
        }
        /// <summary>
        /// Called by the bootstrapper's constructor at runtime to start the framework.
        /// </summary>B
        protected virtual void StartRuntime()
        {
            EventAggregator.HandlerResultProcessing = (target, result) =>
            {
                var task = result as Task;
                if (task != null)
                {
                    result = new IResult[] { task.AsResult() };
                }

                var coroutine = result as IEnumerable<IResult>;
                if (coroutine != null)
                {
                    var viewAware = target as IViewAware;
                    var view = viewAware != null ? viewAware.GetView() : null;
                    var context = new CoroutineExecutionContext { Target = target, View = view };

                    Coroutine.BeginExecute(coroutine.GetEnumerator(), context);
                }
            };

            AssemblySourceCache.Install();
            AssemblySource.Instance.AddRange(SelectAssemblies());

            Configure();

            IoC.GetInstance = GetInstance;
            IoC.GetAllInstances = GetAllInstances;
            IoC.BuildUp = BuildUp;
        }
        public override IResult Execute(IResult previousResults)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(WindowTitle))
                    AdvancedMenuManager.WindowTitle = WindowTitle;

                if (!string.IsNullOrWhiteSpace(DefaultTitle))
                    AdvancedMenuManager.DefaultTitle = DefaultTitle;

                if (!string.IsNullOrWhiteSpace(DefaultDescription))
                    AdvancedMenuManager.DefaultDescription = DefaultDescription;

                if (_leftOffset.HasValue)
                    AdvancedMenuManager.InitialLeftOffset = _leftOffset.Value;

                if (_topOffset.HasValue)
                    AdvancedMenuManager.InitialTopOffset = _topOffset.Value;

                if (!string.IsNullOrWhiteSpace(HelpTopic))
                    AdvancedMenuManager.HelpTopic = HelpTopic;

                return new NextResult();
            }
            catch (Exception e)
            {
                return new ExceptionOccurred(e);
            }
        }
Example #27
0
        public override IResult Execute(IResult previousResults)
        {
            try
            {
                using (var key = Registry.CurrentUser.OpenSubKey(KeyPath, true))
                {
                    if (key == null)
                        return new NextResult();

                    var value = key.GetValue(ValueName).ToIntOrDefault(0);
                    if (value == 0)
                        return new NextResult();

                    key.SetValue(ValueName, 0);
                    Log.InfoFormat("Internet-connection proxy disabled");
                }

                return new NextResult();

            }
            catch (Exception e)
            {
                return new ExceptionOccurred(e);
            }
        }
        public void SetUp()
        {
            var placeholder1 = new Placeholder("area 1");
            var placeholder2 = new Placeholder("area 2");
            var widgetSpecification = new WidgetSpecification("widget");
            widgetSpecification.Insert(0, placeholder1);
            widgetSpecification.Insert(1, placeholder2);

            var area = new Area("area 1");
            var widget = new Widget("widget", new[] { area });

            var buildContext = new BuildData(Enumerable.Empty<IContextItem>());

            var builder = new Builder(RenderingInstructions.BuildForPreview(), w => widgetSpecification, null);

            var instance = widget.Build(builder, new[] { 0 }, buildContext);

            var rendererFactory = MockRepository.GenerateStub<IRendererFactory>();
            this.viewHelper = MockRepository.GenerateStub<IViewHelper>();
            var multiRenderer = new MultiRenderer(rendererFactory);

            KolaConfigurationRegistry.RegisterRenderer(multiRenderer);

            this.result = instance.Render(multiRenderer);
        }
Example #29
0
 public ResultExecutionTask(IResult result, ActionExecutionContext context)
 {
     Result = result;
     Context = context;
     CompletionEventArgs = new ResultCompletionEventArgs();
     ExecutionCompleteWaitHandle = new ManualResetEvent(false);
 }
 public MainViewModel(IApriori apriori, IResult resultWindow)
 {
     _items = new ObservableSet<Item>();
     _transactions = new ObservableCollection<string>();
     this._apriori = apriori;
     this._resultWindow = resultWindow;
 }